{"id":13490068,"url":"https://github.com/sethvargo/go-githubactions","last_synced_at":"2025-05-14T20:03:12.886Z","repository":{"id":38818621,"uuid":"231722229","full_name":"sethvargo/go-githubactions","owner":"sethvargo","description":"Go SDK for GitHub Actions - easily author GitHub Actions in Go","archived":false,"fork":false,"pushed_at":"2025-03-13T20:51:36.000Z","size":95,"stargazers_count":468,"open_issues_count":0,"forks_count":35,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-01T09:19:26.188Z","etag":null,"topics":["actions-sdk","actions-sdk-go","github-actions","github-actions-docker","golang"],"latest_commit_sha":null,"homepage":"","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/sethvargo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-04T06:52:52.000Z","updated_at":"2025-03-30T18:58:15.000Z","dependencies_parsed_at":"2024-06-18T12:40:17.011Z","dependency_job_id":"ae10b7b8-2a3a-4da5-83cc-dfd2f8a78d41","html_url":"https://github.com/sethvargo/go-githubactions","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethvargo%2Fgo-githubactions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethvargo%2Fgo-githubactions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethvargo%2Fgo-githubactions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sethvargo%2Fgo-githubactions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sethvargo","download_url":"https://codeload.github.com/sethvargo/go-githubactions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247819932,"owners_count":21001394,"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":["actions-sdk","actions-sdk-go","github-actions","github-actions-docker","golang"],"created_at":"2024-07-31T19:00:40.227Z","updated_at":"2025-04-08T10:12:48.752Z","avatar_url":"https://github.com/sethvargo.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# GitHub Actions SDK (Go)\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/sethvargo/go-githubactions.svg)](https://pkg.go.dev/github.com/sethvargo/go-githubactions)\n[![unit](https://github.com/sethvargo/go-githubactions/actions/workflows/unit.yml/badge.svg)](https://github.com/sethvargo/go-githubactions/actions/workflows/unit.yml)\n\nThis library provides an SDK for authoring [GitHub Actions][gh-actions] in Go. It has no external dependencies and provides a Go-like interface for interacting with GitHub Actions' build system.\n\n\n## Installation\n\nDownload the library:\n\n```text\n$ go get -u github.com/sethvargo/go-githubactions/...\n```\n\n\n## Usage\n\nThe easiest way to use the library is by importing it and invoking the functions\nat the root:\n\n```go\nimport (\n  \"github.com/sethvargo/go-githubactions\"\n)\n\nfunc main() {\n  val := githubactions.GetInput(\"val\")\n  if val == \"\" {\n    githubactions.Fatalf(\"missing 'val'\")\n  }\n}\n```\n\nYou can also create an instance with custom fields that will be included in log messages:\n\n```go\nimport (\n  \"github.com/sethvargo/go-githubactions\"\n)\n\nfunc main() {\n  actions := githubactions.WithFieldsMap(map[string]string{\n    \"file\": \"myfile.js\",\n    \"line\": \"100\",\n  })\n\n  val := actions.GetInput(\"val\")\n  if val == \"\" {\n    actions.Fatalf(\"missing 'val'\")\n  }\n}\n```\n\nFor more examples and API documentation, please see the [Go docs][godoc].\n\n\n## Publishing\n\nThere are multiple ways to publish GitHub Actions written in Go:\n\n-   [Composite actions](https://github.com/FerretDB/github-actions/blob/2ae30fd2cdb635d8aefdaf9f770257e156c9f77b/extract-docker-tag/action.yml)\n-   [Pre-compiled binaries with a shim](https://full-stack.blend.com/how-we-write-github-actions-in-go.html)\n-   Docker containers (see below)\n\nBy default, GitHub Actions expects actions to be written in Node.js. For other languages like Go, you need to provide a `Dockerfile` and entrypoint instructions in an `action.yml` file:\n\n```dockerfile\n# your-repo/Dockerfile\nFROM golang:1.18\nWORKDIR /src\nCOPY . .\nRUN go build -o /bin/app .\nENTRYPOINT [\"/bin/app\"]\n```\n\n```yaml\n# your-repo/action.yml\nname: My action\nauthor: My name\ndescription: My description\n\nruns:\n  using: docker\n  image: Dockerfile\n```\n\nAnd then users can import your action by the repository name:\n\n```yaml\n# their-repo/.github/workflows/thing.yml\nsteps:\n- name: My action\n  uses: username/repo@latest\n```\n\nHowever, this will clone the entire repo and compile the Go code each time the action runs. Worse, it uses the Go base container which is a few hundred MBs and includes a ton of unnecessary things.\n\nFortunately, GitHub Actions can also source from a Docker container directly from Docker Hub:\n\n```yaml\nsteps:\n- name: My action\n  uses: docker://username/repo:latest\n```\n\nNow we can precompile and publish our Go Action as a Docker container, but we need to make it much, much smaller first. This can be achieved using multi-stage Docker builds:\n\n```dockerfile\nFROM golang:1.18 AS builder\n\nENV GO111MODULE=on \\\n  CGO_ENABLED=0 \\\n  GOOS=linux \\\n  GOARCH=amd64\n\nRUN apt-get -qq update \u0026\u0026 \\\n  apt-get -yqq install upx\n\nWORKDIR /src\nCOPY . .\n\nRUN go build \\\n  -ldflags \"-s -w -extldflags '-static'\" \\\n  -o /bin/app \\\n  . \\\n  \u0026\u0026 strip /bin/app \\\n  \u0026\u0026 upx -q -9 /bin/app\n\nRUN echo \"nobody:x:65534:65534:Nobody:/:\" \u003e /etc_passwd\n\n\n\nFROM scratch\n\nCOPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/\nCOPY --from=builder /etc_passwd /etc/passwd\nCOPY --from=builder --chown=65534:0 /bin/app /app\n\nUSER nobody\nENTRYPOINT [\"/app\"]\n```\n\nThe first step, uses a fat container to build, strip, and compress the compiled Go binary. Then, in the second step, the compiled and compressed binary is copied into a scratch (bare) container along with some SSL certificates and a `nobody` user in which to execute the container.\n\nThis will usually produce an image that is less than 10MB in size, making for\nmuch faster builds.\n\n\n[gh-actions]: https://github.com/features/actions\n[godoc]: https://godoc.org/github.com/sethvargo/go-githubactions\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsethvargo%2Fgo-githubactions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsethvargo%2Fgo-githubactions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsethvargo%2Fgo-githubactions/lists"}