Write Github actions in Go

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: [master]
  push:
    branches: [master]
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

Owner
Eyal Posener
Sittin' on the dock of the bay
Eyal Posener
Similar Resources

generate my_github status using GitHub Actions

generate my_github status using GitHub Actions

generate my_github status using GitHub Actions

Sep 21, 2022

Assume AWS IAM roles from GitHub Actions workflows with no stored secrets

Assume AWS IAM roles from GitHub Actions workflows with no stored secrets

AWS IAM roles for GitHub Actions workflows Background and rationale GitHub Actions are a pretty nice solution for CI/CD. Where they fall short is inte

Feb 12, 2022

GitHub Actions as CI for Go

GitHub Actions for Go GitHub Actions includes CI/CD for free for Open Source repositories.

Jan 4, 2023

GitHub Actions for Feishu

actions-feishu 通过 GitHub Actions 来发送消息到飞书 Quick start Actions 配置样例: - name: feishu notify uses: xiachufang/[email protected] with:

Dec 8, 2022

🚀 Golang, Go Fiber, RabbitMQ, MongoDB, Docker, Kubernetes, GitHub Actions and Digital Ocean

🚀 Golang, Go Fiber, RabbitMQ, MongoDB, Docker, Kubernetes, GitHub Actions and Digital Ocean

Bookings Solução de cadastro de usuários e reservas. Tecnologias Utilizadas Golang MongoDB RabbitMQ Github Actions Docker Hub Docker Kubernetes Digita

Feb 18, 2022

actionlint is a static checker for GitHub Actions workflow files.

actionlint actionlint is a static checker for GitHub Actions workflow files. Features: Syntax check for workflow files to check unexpected or missing

Dec 27, 2022

💲 Golang, Go Fiber, RabbitMQ, MongoDB, Docker, Kubernetes, GitHub Actions

💲 Golang, Go Fiber, RabbitMQ, MongoDB, Docker, Kubernetes, GitHub Actions

Bank Projeto para simular empréstimos financeiros em um banco para clientes Tecnologias Utilizadas Golang MongoDB RabbitMQ Github Actions Docker Hub D

Dec 9, 2022

Schedule daily tweets from markdown files in your repo, posted via github actions.

markdown-tweet-scheduler Schedule daily tweets from markdown files in your repo, posted to twitter via github actions. Setup Fork this repo Get your t

Dec 6, 2022

网易云歌词自动生成《捧读》用的 epub, 帮助学习。(GitHub Actions + shortcuts + telegram)

网易云歌词自动生成《捧读》用的 epub, 帮助学习。(GitHub Actions + shortcuts + telegram)

pengdu_helper 网易云歌词自动生成《捧读》用的 epub, 帮助学习。(GitHub Actions + shortcuts + telegram) 如何使用 前提 有访问自由互联网的环境,有 telegram 请自行查询如何写 telegram bot 有《捧读》app fork 或者

Oct 10, 2022

Minting OIDC tokens from GitHub Actions for use with OpenFaaS

minty Experiment for minting OIDC tokens from GitHub Actions for use with OpenFaaS Why would you want this? Enable third-parties to deploy to your ope

Oct 31, 2021

Auto-updating F-Droid repo using GitHub Actions

Auto-updating F-Droid repo using GitHub Actions

fdroid This repository hosts an F-Droid repo for my apps. This allows you to install and update apps very easily. How to use At first, you should inst

Dec 29, 2022

GitHub Actions demo for a monorepo Go project

GitHub Actions demo for a monorepo Go project The purpose of this repository is to demonstrate using a GitHub action as a pull request status check in

Oct 31, 2021

toghsh translates github actions workflows to shell scripts

togsh - extracts shell commands from github actions workflows toghsh is a helper tool to translate github action workflows into equivalent shell scrip

Nov 16, 2021

CI/CD with Jenkins, GitHub Actions, Travis CI etc

CI/CD with Jenkins, GitHub Actions, Travis CI etc This is a simple repository built using Golang with the main purpose to try out different CI/CD tool

Nov 11, 2021

Proof-of-concept SLSA provenance generator for GitHub Actions

SLSA GitHub Actions Demo A proof-of-concept SLSA provenance generator for GitHub Actions. Background SLSA is a framework intended to codify and promot

Nov 4, 2022

A reverse engineered github actions compatible self-hosted runner using nektos/act to execute your workflow steps

github-act-runner A reverse engineered github actions compatible self-hosted runner using nektos/act to execute your workflow steps. Unlike the offici

Dec 24, 2022

Golang Todo App with rpc protocol,k8s,github actions

Golang Todo App with rpc protocol,k8s,github actions

go-todo-app-rpc Golang Todo App with rpc protocol ,k8s, github actions using docker-compose locally docker-compose build docker-compose up Open http

Nov 28, 2021

Gophercon lab "Get Go-ing with GitHub Actions"

GitHub Action Using Go This is a starting point for a GitHub Action based in Go. This repo provides all the structure needed to build a robust GitHub

Dec 8, 2021

A Simple Bank Web Service implemented in Go, HTTP & GRPC, PostgreSQL, Docker, Kubernetes, GitHub Actions CI

simple-bank Based on this Backend Master Class by TECH SCHOOL: https://youtube.com/playlist?list=PLy_6D98if3ULEtXtNSY_2qN21VCKgoQAE Requirements Insta

Dec 9, 2021
Comments
  • goaction.Setenv is using a deprecated API

    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

    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.

:octocat: lazyhub - Terminal UI Client for GitHub using gocui.
:octocat: lazyhub - Terminal UI Client for GitHub using gocui.

lazyhub lazyhub - Terminal UI Client for GitHub using gocui. Demo Features ?? Check the trending repositories on GitHub today ?? Search repositories ?

Dec 14, 2022
A simple tool to help apply changes across many GitHub repositories simultaneously
A simple tool to help apply changes across many GitHub repositories simultaneously

A simple tool to help apply changes across many GitHub repositories simultaneously

Dec 22, 2022
backup data (code, comments, issues) from github

github-backup Backup your GitHub repositories (including issues and comments). The backup will include a copy of the git repository itself (a bare, mi

Nov 21, 2021
This github action find the Issues linked in a Pull Request.

Linked Issue (Github Action) This action find the Issues linked in a Pull Request. It parses the HTML of the PR page to find the linked issues. Inputs

Jun 30, 2022
A Github Action that verify if your README.md has broken links

A GitHub Action that automatically check if some link in your README.md is broken or not responding.

Nov 10, 2022
Find trending repositories on GitHub
Find trending repositories on GitHub

octotrends.com A niftly little tool I wrote to try and find repos and languages that are rapidly growing on GitHub. Growth rates are based on % growth

Jun 14, 2022
github-actions-merger is github actions that merges pull request with commit message including pull request labels.

github-actions-merger github-actions-merger is github actions that merges pull request with commit message including pull request labels. Usage Write

Dec 7, 2022
Write Github actions in Go

goaction 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 Git

Dec 20, 2022
A simple Go app and GitHub workflow that shows how to use GitHub Actions to test, build and deploy a Go app to Docker Hub

go-pipeline-demo A repository containing a simple Go app and GitHub workflow that shows how to use GitHub Actions to test, build and deploy a Go app t

Nov 17, 2021
Write controller-runtime based k8s controllers that read/write to git, not k8s

Git Backed Controller The basic idea is to write a k8s controller that runs against git and not k8s apiserver. So the controller is reading and writin

Dec 10, 2021