Giter Site home page Giter Site logo

goaction's Introduction

goaction

GoDoc

Package goaction enables writing Github Actions in Go.

The idea is: write a standard Go script, one that works with go run, and use it as Github action. The script's inputs - flags and environment variables, are set though the Github action API. This project will generate all the required files for the script (This generation can be done automattically with Github action integration). The library also exposes neat API to get workflow information.

Required Steps

  • Write a Go script.

  • Add goaction configuration in .github/workflows/goaction.yml.

  • Push the project to Github.

See simplest example for a Goaction script: posener/goaction-example, or an example that demonstrait using Github APIs: posener/goaction-issues-example.

Writing a Goaction Script

Write Github Action by writing Go code! Just start a Go module with a main package, and execute it as a Github action using Goaction, or from the command line using go run.

A go executable can get inputs from the command line flag and from environment variables. Github actions should have a action.yml file that defines this API. Goaction bridges the gap by parsing the Go code and creating this file automatically for you.

The main package inputs should be defined with the standard flag package for command line arguments, or by os.Getenv for environment variables. These inputs define the API of the program and goaction automatically detect them and creates the action.yml file from them.

Additionally, goaction also provides a library that exposes all Github action environment in an easy-to-use API. See the documentation for more information.

Code segments which should run only in Github action (called "CI mode"), and not when the main package runs as a command line tool, should be protected by a if goaction.CI { ... } block.

Goaction Configuration

In order to convert the repository to a Github action, goaction command line should run on the "main file" (described above). This command can run manually (by ./cmd/goaction) but luckily goaction also comes as a Github action :-)

Goaction Github action keeps the Github action file updated according to the main Go file automatically. When a PR is made, goaction will post a review explaining what changes to expect. When a new commit is pushed, Goaction makes sure that the Github action files are updated if needed.

Add the following content to .github/workflows/goaction.yml

on:
  pull_request:
    branches: [main]
  push:
    branches: [main]
permissions:
  # Goaction needs permissions to update pull requests comments and update contents.
  pull-requests: write
  contents: write
jobs:
  goaction:
    runs-on: ubuntu-latest
    steps:
    - name: Check out repository
      uses: actions/checkout@v2
    - name: Update action files
      uses: posener/goaction@v1
      with:
        # Optional: required only for commenting on PRs.
        github-token: '${{ secrets.GITHUB_TOKEN }}'
    # Optional: now that the script is a Github action, it is possible to run it in the
    # workflow.
    - name: Example
      uses: [./](./)

Goaction Artifacts

./action.yml: A "metadata" file for Github actions. If this file exists, the repository is considered as Github action, and the file contains information that instructs how to invoke this action. See metadata syntax. for more info.

./Dockerfile: A file that contains instructions how to build a container, that is used for Github actions. Github action uses this file in order to create a container image to the action. The container can also be built and tested manually:

$ docker build -t my-action .
$ docker run --rm my-action

Annotations

Goaction parses Go script file and looks for annotations that extends the information that exists in the function calls. Goaction annotations are a comments that start with //goaction: (no space after slashes). They can only be set on a var definition. The following annotations are available:

  • //goaction:required - sets an input definition to be "required".

  • //goaction:skip - skips an input out output definition.

  • //goaction:description <description> - add description for os.Getenv.

  • //goaction:default <value> - add default value for os.Getenv.

Using Goaction

A list of projects which are using Goaction (please send a PR if your project uses goaction and does not appear her).

Sub Packages

  • actionutil: Package actionutil provides utility functions for Github actions.

  • log: Package log is an alternative package for standard library "log" package for logging in Github action environment.


Readme created from Go doc with goreadme

goaction's People

Contributors

posener avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

goaction's Issues

goaction.Setenv is using a deprecated API

The testworkflow.yml fails on the following error:

Error: Unable to process command '::set-env name=set::set' successfully.
Error: The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
Error: Unable to process command '::set-env name=export::export' successfully.
Error: The `set-env` command is disabled. Please upgrade to using Environment Files or opt into unsecure command execution by setting the `ACTIONS_ALLOW_UNSECURE_COMMANDS` environment variable to `true`. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

Instructions in https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#environment-files

Env should be appended to a file located under $GITHUB_ENV path as <key>=<value>\n.

Greetings from ezactions

It looks like we both started on the same thing at about the same time. I've been hacking on ezactions for a couple of days and discovered goaction when I came to your profile page while trying to remember the name of goreadme.

I tried out goaction with a simple hello world service, and it looks good. It's very easy to get started with minimal code.

ezactions takes a little different approach by using the Action struct to set inputs and outputs instead of inspecting the code. I considered using struct tags for configuration, but I hadn't considered using flags. That's a great idea.

You might want to consider adding something like WorkflowCommander to make outputs and logging easier to use. I can make a PR if you're interested, or you can just copy the code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.