Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GitHub Actions as CI for Go

License

NotificationsYou must be signed in to change notification settings

mvdan/github-actions-golang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Actions includes CI/CD for freefor Open Source repositories. This document contains information on making itwork well forGo. See theminaction:

$ cat .github/workflows/test.ymlon:[push, pull_request]name:Testjobs:test:strategy:matrix:go-version:[1.23.x, 1.24.x]os:[ubuntu-latest, macos-latest, windows-latest]runs-on:${{ matrix.os }}steps:    -uses:actions/checkout@v4    -uses:actions/setup-go@v5with:go-version:${{ matrix.go-version }}    -run:go test ./...

Summary

Each workflow file has a number of jobs, which get runon specified events,and run concurrently with each other. You can have workflowstatus badges.

Eachjob runs on a configurationmatrix. For example, we can test two majorGo versions on three operating systems.

Each job has a number ofsteps, such as installing Go, or checking out therepository's code.

Note thatname fields are optional.

FAQs

How do I set environment variables?

They can be set up viaenv for anentireworkflow,a job, or for each step:

env:GOPROXY:"https://proxy.company.com"jobs:[...]

How do I set environment variables at run-time?

You can useenvironment filesto set environment variables or add an element to$PATH. For example:

steps:-name:Set env varsrun:|      echo "CGO_ENABLED=0" >> $GITHUB_ENV      echo "${HOME}/goroot/bin" >> $GITHUB_PATH

Note that these take effect for future steps in the job.

How do I set up caching between builds?

Since v4,actions/setup-go cachesGOCACHEandGOMODCACHE automatically, usinggo.sum as the cache key.You can turn that off viacache: false, and then you may also use your owncustom caching, for example to only keepGOMODCACHE:

-uses:actions/cache@v3with:path:~/go/pkg/modkey:${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}restore-keys:|      ${{ runner.os }}-go-

Seethis guidefor more details.

How do I run a step conditionally?

You can useif conditionals, using theircustom expressionlanguage:

-if:github.event_name == 'push' && matrix.os == 'ubuntu-latest'run:go run ./endtoend

How do I set up a custom build matrix?

You caninclude extra matrixjobs,and you canexclude specific matrixjobs.

How do I run multiline scripts?

-name:Series of commandsrun:|    go test ./...    go test -race ./...

Should I use two workflows, or two jobs on one workflow?

The biggest difference is the UI; workflow results are shown separately.Grouping jobs in workflows can also be useful if one wants to customize theworkflow triggers, or to set up dependencies vianeeds.

How do I set up a secret environment variable?

Followthese stepsto set up the secret in the repo's settings. After adding a secret likeFOO_SECRET, use it on a step as follows:

-run:some-commandenv:FOO_SECRET:${{ secrets.FOO_SECRET }}

How do I install private modules?

It's possible to install modules from private GitHub repositories without usingyour own proxy. You'll need to add apersonal access token as a secretenvironment variable, as well as configureGOPRIVATE.You can also directly used the tokenprovided by GitHubin the workflow.You can define anything as username in the URL, it is not taken into account by GitHub.

-name:Configure git for private modulesenv:TOKEN:${{ secrets.PERSONAL_ACCESS_TOKEN }}run:git config --global url."https://user:${TOKEN}@github.com".insteadOf "https://github.com"
env:GOPRIVATE:"*.company.com"jobs:[...]

How do I install Linux packages?

Usesudo apt, making sure to only run the step on Linux:

-if:matrix.os == 'ubuntu-latest'run:sudo apt update && sudo apt install -y --no-install-recommends mypackage

Quick links

Caveats

git config core.autocrlf defaults to true, so be careful about CRLF endings inyour plaintexttestdata files on Windows. To work around this, set up thefollowing.gitattributes:

*-text

About

GitHub Actions as CI for Go

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors11

Languages


[8]ページ先頭

©2009-2025 Movatter.jp