{"id":13694370,"url":"https://github.com/posener/goaction","last_synced_at":"2025-04-09T21:18:29.601Z","repository":{"id":48853443,"uuid":"259149416","full_name":"posener/goaction","owner":"posener","description":"Write Github actions in Go","archived":false,"fork":false,"pushed_at":"2022-09-09T08:07:09.000Z","size":112,"stargazers_count":214,"open_issues_count":2,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T21:18:24.638Z","etag":null,"topics":["action","github","github-action","go","golang","script"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/posener.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-26T22:47:59.000Z","updated_at":"2025-03-14T23:34:19.000Z","dependencies_parsed_at":"2023-01-05T05:01:47.114Z","dependency_job_id":null,"html_url":"https://github.com/posener/goaction","commit_stats":{"total_commits":84,"total_committers":1,"mean_commits":84.0,"dds":0.0,"last_synced_commit":"77fafdc60c2b793ce1ea10fd9886157c90db7204"},"previous_names":["posener/goactions"],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fgoaction","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fgoaction/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fgoaction/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posener%2Fgoaction/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posener","download_url":"https://codeload.github.com/posener/goaction/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111973,"owners_count":21049578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["action","github","github-action","go","golang","script"],"created_at":"2024-08-02T17:01:30.330Z","updated_at":"2025-04-09T21:18:29.579Z","avatar_url":"https://github.com/posener.png","language":"Go","readme":"# goaction\n\n[![GoDoc](https://img.shields.io/badge/pkg.go.dev-doc-blue)](http://pkg.go.dev/github.com/posener/goaction)\n\nPackage goaction enables writing Github Actions in Go.\n\nThe idea is: write a standard Go script, one that works with `go run`, and use it as Github action.\nThe script's inputs - flags and environment variables, are set though the Github action API. This\nproject will generate all the required files for the script (This generation can be done\nautomattically with Github action integration). The library also exposes neat API to get workflow\ninformation.\n\n## Required Steps\n\n- [x] Write a Go script.\n\n- [x] Add `goaction` configuration in `.github/workflows/goaction.yml`.\n\n- [x] Push the project to Github.\n\nSee simplest example for a Goaction script: [posener/goaction-example](https://github.com/posener/goaction-example),\nor an example that demonstrait using Github APIs: [posener/goaction-issues-example](https://github.com/posener/goaction-issues-example).\n\n## Writing a Goaction Script\n\nWrite Github Action by writing Go code! Just start a Go module with a main package, and execute it\nas a Github action using Goaction, or from the command line using `go run`.\n\nA go executable can get inputs from the command line flag and from environment variables. Github\nactions should have a `action.yml` file that defines this API. Goaction bridges the gap by parsing\nthe Go code and creating this file automatically for you.\n\nThe main package inputs should be defined with the standard `flag` package for command line\narguments, or by `os.Getenv` for environment variables. These inputs define the API of the program\nand `goaction` automatically detect them and creates the `action.yml` file from them.\n\nAdditionally, goaction also provides a library that exposes all Github action environment in an\neasy-to-use API. See the documentation for more information.\n\nCode segments which should run only in Github action (called \"CI mode\"), and not when the main\npackage runs as a command line tool, should be protected by a `if goaction.CI { ... }` block.\n\n## Goaction Configuration\n\nIn order to convert the repository to a Github action, goaction command line should run on the\n**\"main file\"** (described above). This command can run manually (by [./cmd/goaction](./cmd/goaction)) but luckily\n`goaction` also comes as a Github action :-)\n\nGoaction Github action keeps the Github action file updated according to the main Go file\nautomatically. When a PR is made, goaction will post a review explaining what changes to expect.\nWhen a new commit is pushed, Goaction makes sure that the Github action files are updated if needed.\n\nAdd the following content to `.github/workflows/goaction.yml`\n\n```go\non:\n  pull_request:\n    branches: [main]\n  push:\n    branches: [main]\npermissions:\n  # Goaction needs permissions to update pull requests comments and update contents.\n  pull-requests: write\n  contents: write\njobs:\n  goaction:\n    runs-on: ubuntu-latest\n    steps:\n    - name: Check out repository\n      uses: actions/checkout@v2\n    - name: Update action files\n      uses: posener/goaction@v1\n      with:\n        # Optional: required only for commenting on PRs.\n        github-token: '${{ secrets.GITHUB_TOKEN }}'\n    # Optional: now that the script is a Github action, it is possible to run it in the\n    # workflow.\n    - name: Example\n      uses: [./](./)\n```\n\n## Goaction Artifacts\n\n[./action.yml](./action.yml): A \"metadata\" file for Github actions. If this file exists, the repository is\nconsidered as Github action, and the file contains information that instructs how to invoke this\naction. See [metadata syntax](https://help.github.com/en/actions/building-actions/metadata-syntax-for-github-actions).\nfor more info.\n\n[./Dockerfile](./Dockerfile): A file that contains instructions how to build a container, that is used for Github\nactions. Github action uses this file in order to create a container image to the action. The\ncontainer can also be built and tested manually:\n\n```go\n$ docker build -t my-action .\n$ docker run --rm my-action\n```\n\n## Annotations\n\nGoaction parses Go script file and looks for annotations that extends the information that exists in\nthe function calls. Goaction annotations are a comments that start with `//goaction:` (no space\nafter slashes). They can only be set on a `var` definition. The following annotations are available:\n\n* `//goaction:required` - sets an input definition to be \"required\".\n\n* `//goaction:skip` - skips an input out output definition.\n\n* `//goaction:description \u003cdescription\u003e` - add description for `os.Getenv`.\n\n* `//goaction:default \u003cvalue\u003e` - add default value for `os.Getenv`.\n\n## Using Goaction\n\nA list of projects which are using Goaction (please send a PR if your project uses goaction and does\nnot appear her).\n\n* [posener/goreadme](http://github.com/posener/goreadme)\n\n## Sub Packages\n\n* [actionutil](./actionutil): Package actionutil provides utility functions for Github actions.\n\n* [log](./log): Package log is an alternative package for standard library \"log\" package for logging in Github action environment.\n\n---\nReadme created from Go doc with [goreadme](https://github.com/posener/goreadme)\n","funding_links":[],"categories":["开源类库","Open source library","Go"],"sub_categories":["Git"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposener%2Fgoaction","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposener%2Fgoaction","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposener%2Fgoaction/lists"}