mirror of
https://github.com/actions/setup-go.git
synced 2026-02-04 06:28:21 +00:00
Enhance workflow for Go setup and caching
Updated GitHub Actions workflow for Go and Webpack builds, including caching and version management.
This commit is contained in:
parent
ae252ee6fb
commit
284eb3b2fa
1 changed files with 233 additions and 0 deletions
233
.github/workflows/webpack.yml
vendored
Normal file
233
.github/workflows/webpack.yml
vendored
Normal file
|
|
@ -0,0 +1,233 @@
|
||||||
|
name: NodeJS with Webpack
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [18.x, 20.x, 22.x]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
npm install
|
||||||
|
npx webpack
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '1.23'
|
||||||
|
- run: go version
|
||||||
|
go 1.23.0 // Minimum required version
|
||||||
|
toolchain go1.23.2 // V6 uses this exact version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '1.23'
|
||||||
|
- run: go run hello.go
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '>=1.22.0'
|
||||||
|
- run: go version
|
||||||
|
go-version: '^1.23.1' # The Go version to download (if necessary) and use.
|
||||||
|
- run: go version
|
||||||
|
go-version: '1.22' # Correct
|
||||||
|
go-version: 1.22 # Incorrect - YAML parser interprets as 1.2
|
||||||
|
# RC version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '1.24.0-rc.1' # The Go version to download (if necessary) and use
|
||||||
|
- run: go version
|
||||||
|
# Beta version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '1.23.0-beta.1' # The Go version to download (if necessary) and use
|
||||||
|
- run: go version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: 'stable' # Latest stable version
|
||||||
|
- run: go version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: 'oldstable' # Previous stable version
|
||||||
|
- run: go version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version-file: 'go.mod'
|
||||||
|
- run: go version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version-file: 'go.work'
|
||||||
|
- run: go version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version-file: '.go-version'
|
||||||
|
- run: go version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version-file: '.tool-versions'
|
||||||
|
- run: go version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '1.23'
|
||||||
|
check-latest: true # Always check for the latest patch release
|
||||||
|
- run: go version
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '1.23'
|
||||||
|
# cache: true (default)
|
||||||
|
- run: go run hello.go
|
||||||
|
const cache = require('@actions/cache');
|
||||||
|
const paths = [
|
||||||
|
'node_modules',
|
||||||
|
'packages/*/node_modules/'
|
||||||
|
]
|
||||||
|
const key = 'npm-foobar-d5ea0750'
|
||||||
|
const cacheId = await cache.saveCache(paths, key)
|
||||||
|
const cache = require('@actions/cache');
|
||||||
|
const paths = [
|
||||||
|
'node_modules',
|
||||||
|
'packages/*/node_modules/'
|
||||||
|
]
|
||||||
|
const key = 'npm-foobar-d5ea0750'
|
||||||
|
const restoreKeys = [
|
||||||
|
'npm-foobar-',
|
||||||
|
'npm-'
|
||||||
|
]
|
||||||
|
const cacheKey = await cache.restoreCache(paths, key, restoreKeys)
|
||||||
|
# In some workflows, you may want to restore a cache without saving it. This can help reduce cache writes and storage usage in workflows that only need to read from cache
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- name: Setup Go
|
||||||
|
id: setup-go
|
||||||
|
uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '1.24.10'
|
||||||
|
cache: false
|
||||||
|
# Capture Go cache locations
|
||||||
|
- name: Set Go cache variables (Linux/macOS)
|
||||||
|
if: runner.os != 'Windows'
|
||||||
|
run: |
|
||||||
|
echo "GO_MOD_CACHE=$(go env GOMODCACHE)" >> $GITHUB_ENV
|
||||||
|
echo "GO_BUILD_CACHE=$(go env GOCACHE)" >> $GITHUB_ENV
|
||||||
|
- name: Set Go cache variables (Windows)
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
echo "GO_MOD_CACHE=$(go env GOMODCACHE)" | Out-File $env:GITHUB_ENV -Append
|
||||||
|
echo "GO_BUILD_CACHE=$(go env GOCACHE)" | Out-File $env:GITHUB_ENV -Append
|
||||||
|
# Normalize runner.arch to lowercase to ensure consistent cache keys
|
||||||
|
- name: Normalize runner architecture (Linux/macOS)
|
||||||
|
if: runner.os != 'Windows'
|
||||||
|
shell: bash
|
||||||
|
run: echo "ARCH=$(echo '${{ runner.arch }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
|
||||||
|
- name: Normalize runner architecture (Windows)
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
shell: pwsh
|
||||||
|
run: |
|
||||||
|
$arch = "${{ runner.arch }}".ToLower()
|
||||||
|
echo "ARCH=$arch" | Out-File $env:GITHUB_ENV -Append
|
||||||
|
- name: Set cache OS suffix for Linux
|
||||||
|
if: runner.os == 'Linux'
|
||||||
|
shell: bash
|
||||||
|
run: echo "CACHE_OS_SUFFIX=$ImageOS-" >> $GITHUB_ENV
|
||||||
|
- name: Restore Go cache
|
||||||
|
id: go-cache
|
||||||
|
uses: actions/cache/restore@v5
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
${{ env.GO_MOD_CACHE }}
|
||||||
|
${{ env.GO_BUILD_CACHE }}
|
||||||
|
key: setup-go-${{ runner.os }}-${{ env.ARCH }}-${{ env.CACHE_OS_SUFFIX }}go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('**/go.sum') }}
|
||||||
|
- name: Download modules
|
||||||
|
run: go mod download
|
||||||
|
- name: Build
|
||||||
|
run: go build ./...
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go-version: ['1.21', '1.22', '1.23']
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go-version }}
|
||||||
|
- run: go test ./...1.23.2
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
# Version or version range of Go to use
|
||||||
|
go-version: '1.23'
|
||||||
|
|
||||||
|
# Path to go.mod, go.work, .go-version, or .tool-versions file
|
||||||
|
go-version-file: 'go.mod'
|
||||||
|
|
||||||
|
# Check for latest version
|
||||||
|
check-latest: false
|
||||||
|
|
||||||
|
# GitHub token for authentication
|
||||||
|
token: ${{ github.token }}
|
||||||
|
|
||||||
|
# Enable/disable caching
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
# Path to dependency files for caching
|
||||||
|
cache-dependency-path: 'go.sum'
|
||||||
|
|
||||||
|
# Architecture to install (auto-detected if not specified)
|
||||||
|
architecture: 'x64'
|
||||||
|
uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
||||||
|
go-version: '1.23'
|
||||||
|
permissions:
|
||||||
|
contents: read # Required to checkout code and install dependencies
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue