mirror of
https://github.com/actions/setup-go.git
synced 2026-07-07 17:05:42 +00:00
Compare commits
1 Commits
3256b766c6
...
084a1b8654
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
084a1b8654 |
@ -1,6 +0,0 @@
|
|||||||
# Ignore list
|
|
||||||
/*
|
|
||||||
|
|
||||||
# Do not ignore these folders:
|
|
||||||
!__tests__/
|
|
||||||
!src/
|
|
||||||
51
.eslintrc.js
51
.eslintrc.js
@ -1,51 +0,0 @@
|
|||||||
// This is a reusable configuration file copied from https://github.com/actions/reusable-workflows/tree/main/reusable-configurations. Please don't make changes to this file as it's the subject of an automatic update.
|
|
||||||
module.exports = {
|
|
||||||
extends: [
|
|
||||||
'eslint:recommended',
|
|
||||||
'plugin:@typescript-eslint/recommended',
|
|
||||||
'plugin:eslint-plugin-jest/recommended',
|
|
||||||
'eslint-config-prettier'
|
|
||||||
],
|
|
||||||
parser: '@typescript-eslint/parser',
|
|
||||||
plugins: ['@typescript-eslint', 'eslint-plugin-node', 'eslint-plugin-jest'],
|
|
||||||
rules: {
|
|
||||||
'@typescript-eslint/no-require-imports': 'error',
|
|
||||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
||||||
'@typescript-eslint/no-explicit-any': 'off',
|
|
||||||
'@typescript-eslint/no-empty-function': 'off',
|
|
||||||
'@typescript-eslint/ban-ts-comment': [
|
|
||||||
'error',
|
|
||||||
{
|
|
||||||
'ts-ignore': 'allow-with-description'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'no-console': 'error',
|
|
||||||
'yoda': 'error',
|
|
||||||
'prefer-const': [
|
|
||||||
'error',
|
|
||||||
{
|
|
||||||
destructuring: 'all'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'no-control-regex': 'off',
|
|
||||||
'no-constant-condition': ['error', {checkLoops: false}],
|
|
||||||
'node/no-extraneous-import': 'error'
|
|
||||||
},
|
|
||||||
overrides: [
|
|
||||||
{
|
|
||||||
files: ['**/*{test,spec}.ts'],
|
|
||||||
rules: {
|
|
||||||
'@typescript-eslint/no-unused-vars': 'off',
|
|
||||||
'jest/no-standalone-expect': 'off',
|
|
||||||
'jest/no-conditional-expect': 'off',
|
|
||||||
'no-console': 'off',
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
env: {
|
|
||||||
node: true,
|
|
||||||
es6: true,
|
|
||||||
'jest/globals': true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -1,2 +1,2 @@
|
|||||||
* text=auto eol=lf
|
* text=auto
|
||||||
.licenses/** -diff linguist-generated=true
|
.licenses/** -diff linguist-generated=true
|
||||||
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -7,7 +7,7 @@ assignees: ''
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<!--- Please direct any generic questions related to actions to our support community forum at https://github.com/orgs/community/discussions/categories/actions --->
|
<!--- Please direct any generic questions related to actions to our support community forum at https://github.community/c/code-to-cloud/github-actions/41 --->
|
||||||
<!--- Before opening up a new bug report, please make sure to check for similar existing issues -->
|
<!--- Before opening up a new bug report, please make sure to check for similar existing issues -->
|
||||||
|
|
||||||
**Description:**
|
**Description:**
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
2
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@ -5,7 +5,7 @@ title: ''
|
|||||||
labels: feature request, needs triage
|
labels: feature request, needs triage
|
||||||
assignees: ''
|
assignees: ''
|
||||||
---
|
---
|
||||||
<!--- Please direct any generic questions related to actions to our support community forum at https://github.com/orgs/community/discussions/categories/actions --->
|
<!--- Please direct any generic questions related to actions to our support community forum at https://github.community/c/code-to-cloud/github-actions/41 --->
|
||||||
<!--- Before opening up a new feature request, please make sure to check for similar existing issues and pull requests -->
|
<!--- Before opening up a new feature request, please make sure to check for similar existing issues and pull requests -->
|
||||||
|
|
||||||
**Description:**
|
**Description:**
|
||||||
|
|||||||
22
.github/dependabot.yml
vendored
22
.github/dependabot.yml
vendored
@ -1,22 +0,0 @@
|
|||||||
# To get started with Dependabot version updates, you'll need to specify which
|
|
||||||
# package ecosystems to update and where the package manifests are located.
|
|
||||||
# Please see the documentation for all configuration options:
|
|
||||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
||||||
|
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
# Enable version updates for npm
|
|
||||||
- package-ecosystem: 'npm'
|
|
||||||
# Look for `package.json` and `lock` files in the `root` directory
|
|
||||||
directory: '/'
|
|
||||||
# Check the npm registry for updates every day (weekdays)
|
|
||||||
schedule:
|
|
||||||
interval: 'weekly'
|
|
||||||
|
|
||||||
# Enable version updates for GitHub Actions
|
|
||||||
- package-ecosystem: 'github-actions'
|
|
||||||
# Workflow files stored in the default location of `.github/workflows`
|
|
||||||
# You don't need to specify `/.github/workflows` for `directory`. You can use `directory: "/"`.
|
|
||||||
directory: '/'
|
|
||||||
schedule:
|
|
||||||
interval: 'weekly'
|
|
||||||
2
.github/workflows/basic-validation.yml
vendored
2
.github/workflows/basic-validation.yml
vendored
@ -14,5 +14,3 @@ jobs:
|
|||||||
call-basic-validation:
|
call-basic-validation:
|
||||||
name: Basic validation
|
name: Basic validation
|
||||||
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
|
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
|
||||||
with:
|
|
||||||
node-version: '24.x'
|
|
||||||
|
|||||||
2
.github/workflows/check-dist.yml
vendored
2
.github/workflows/check-dist.yml
vendored
@ -15,5 +15,3 @@ jobs:
|
|||||||
call-check-dist:
|
call-check-dist:
|
||||||
name: Check dist/
|
name: Check dist/
|
||||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
||||||
with:
|
|
||||||
node-version: '24.x'
|
|
||||||
|
|||||||
20
.github/workflows/publish-immutable-actions.yml
vendored
20
.github/workflows/publish-immutable-actions.yml
vendored
@ -1,20 +0,0 @@
|
|||||||
name: 'Publish Immutable Action Version'
|
|
||||||
|
|
||||||
on:
|
|
||||||
release:
|
|
||||||
types: [published]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
publish:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
id-token: write
|
|
||||||
packages: write
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checking out
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
- name: Publish
|
|
||||||
id: publish
|
|
||||||
uses: actions/publish-immutable-action@v0.0.4
|
|
||||||
@ -22,7 +22,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Update the ${{ env.TAG_NAME }} tag
|
- name: Update the ${{ env.TAG_NAME }} tag
|
||||||
uses: actions/publish-action@v0.4.0
|
uses: actions/publish-action@v0.2.2
|
||||||
with:
|
with:
|
||||||
source-tag: ${{ env.TAG_NAME }}
|
source-tag: ${{ env.TAG_NAME }}
|
||||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|||||||
11
.github/workflows/update-config-files.yml
vendored
11
.github/workflows/update-config-files.yml
vendored
@ -1,11 +0,0 @@
|
|||||||
name: Update configuration files
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
- cron: '0 3 * * 0'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
call-update-configuration-files:
|
|
||||||
name: Update configuration files
|
|
||||||
uses: actions/reusable-workflows/.github/workflows/update-config-files.yml@main
|
|
||||||
107
.github/workflows/versions.yml
vendored
107
.github/workflows/versions.yml
vendored
@ -18,9 +18,9 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Go Stable
|
- name: Setup Go Stable
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@ -33,9 +33,9 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Go oldStable
|
- name: Setup Go oldStable
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@ -48,16 +48,14 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
version: [stable, oldstable]
|
version: [stable, oldstable]
|
||||||
architecture: [x64, x32]
|
architecture: [x64, x32]
|
||||||
exclude:
|
exclude:
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
architecture: x32
|
architecture: x32
|
||||||
- os: macos-latest-large
|
|
||||||
architecture: x32
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }}
|
- name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }}
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@ -72,17 +70,11 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest, macos-latest-large]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
go: [1.21.13, 1.22.8, 1.23.2]
|
go: [1.17, 1.18, 1.19]
|
||||||
include:
|
|
||||||
- os: windows-latest
|
|
||||||
go: 1.20.14
|
|
||||||
exclude:
|
|
||||||
- os: windows-latest
|
|
||||||
go: 1.23.2
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup-go ${{ matrix.go }}
|
- name: setup-go ${{ matrix.go }}
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -98,10 +90,10 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
go-version: ['1.20', '1.21', '1.22', '1.23']
|
go-version: [1.16, 1.17]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Go and check latest
|
- name: Setup Go and check latest
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
@ -115,15 +107,15 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Go and check latest
|
- name: Setup Go and check latest
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
go-version-file: __tests__/data/go.mod
|
go-version-file: __tests__/data/go.mod
|
||||||
- name: verify go
|
- name: verify go
|
||||||
run: __tests__/verify-go.sh 1.20.14
|
run: __tests__/verify-go.sh 1.14
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
go-version-file-with-gowork:
|
go-version-file-with-gowork:
|
||||||
@ -131,59 +123,28 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Go and check latest
|
- name: Setup Go and check latest
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
go-version-file: __tests__/data/go.work
|
go-version-file: __tests__/data/go.work
|
||||||
- name: verify go
|
- name: verify go
|
||||||
run: __tests__/verify-go.sh 1.21
|
run: __tests__/verify-go.sh 1.19
|
||||||
shell: bash
|
|
||||||
|
|
||||||
go-version-file-with-tool-versions:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- name: Setup Go and check latest
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version-file: __tests__/data/.tool-versions
|
|
||||||
- name: verify go
|
|
||||||
run: __tests__/verify-go.sh 1.23.2
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
go-version-file-with-go-version:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- name: Setup Go from .go-version file
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version-file: __tests__/data/.go-version
|
|
||||||
- name: verify go
|
|
||||||
run: __tests__/verify-go.sh 1.22.4
|
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
setup-versions-from-manifest:
|
setup-versions-from-manifest:
|
||||||
|
name: Setup ${{ matrix.go }} ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest, macos-latest-large]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
go: [1.20.14, 1.21.10, 1.22.8, 1.23.2]
|
go: [1.12.16, 1.13.11, 1.14.3]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup-go ${{ matrix.go }}
|
- name: setup-go ${{ matrix.go }}
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -195,15 +156,16 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
setup-versions-from-dist:
|
setup-versions-from-dist:
|
||||||
|
name: Setup ${{ matrix.go }} ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [windows-latest, ubuntu-latest, macos-latest-large]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
go: [1.11.12]
|
go: [1.9, 1.8.6]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup-go ${{ matrix.go }}
|
- name: setup-go ${{ matrix.go }}
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -219,23 +181,14 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest, macos-latest-large]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
go-version: [1.20.14, 1.21, 1.22, 1.23]
|
go-version: [1.16, 1.17]
|
||||||
include:
|
|
||||||
- os: macos-latest
|
|
||||||
architecture: arm64
|
|
||||||
- os: ubuntu-latest
|
|
||||||
architecture: x64
|
|
||||||
- os: windows-latest
|
|
||||||
architecture: x64
|
|
||||||
- os: macos-latest-large
|
|
||||||
architecture: x64
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v3
|
||||||
- name: Setup Go and check latest
|
- name: Setup Go and check latest
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go-version }}
|
go-version: ${{ matrix.go-version }}
|
||||||
architecture: ${{ matrix.architecture }}
|
architecture: x64
|
||||||
- name: Verify Go
|
- name: Verify Go
|
||||||
run: go version
|
run: go version
|
||||||
|
|||||||
136
.github/workflows/windows-validation.yml
vendored
136
.github/workflows/windows-validation.yml
vendored
@ -1,136 +0,0 @@
|
|||||||
name: Validate Windows installation
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
create-link-if-not-default:
|
|
||||||
runs-on: windows-latest
|
|
||||||
name: 'Validate if symlink is created'
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
cache: [false, true]
|
|
||||||
go: [1.20.1]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: 'Setup ${{ matrix.cache }}, cache: ${{ matrix.go }}'
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go }}
|
|
||||||
cache: ${{ matrix.cache }}
|
|
||||||
|
|
||||||
- name: 'Drive C: should have zero size link'
|
|
||||||
run: |
|
|
||||||
du -m -s 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'
|
|
||||||
# make sure drive c: contains only a link
|
|
||||||
size=$(du -m -s 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'|cut -f1 -d$'\t')
|
|
||||||
if [ $size -ne 0 ];then
|
|
||||||
echo 'Size of the link created on drive c: must be 0'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
# Drive D: is small, take care the action does not eat up the space
|
|
||||||
- name: 'Drive D: space usage should be below 1G'
|
|
||||||
run: |
|
|
||||||
du -m -s 'D:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'
|
|
||||||
size=$(du -m -s 'D:\hostedtoolcache\windows\go\${{ matrix.go }}\x64'|cut -f1 -d$'\t')
|
|
||||||
# make sure archive does not take lot of space
|
|
||||||
if [ $size -gt 999 ];then
|
|
||||||
echo 'Size of installed on drive d: go is too big';
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
# make sure the Go installation has not been changed to the end user
|
|
||||||
- name: Test paths and environments
|
|
||||||
run: |
|
|
||||||
echo $PATH
|
|
||||||
which go
|
|
||||||
go version
|
|
||||||
go env
|
|
||||||
if [ $(which go) != '/c/hostedtoolcache/windows/go/${{ matrix.go }}/x64/bin/go' ];then
|
|
||||||
echo 'which go should return "/c/hostedtoolcache/windows/go/${{ matrix.go }}/x64/bin/go"'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [ $(go env GOROOT) != 'C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64' ];then
|
|
||||||
echo 'go env GOROOT should return "C:\hostedtoolcache\windows\go\${{ matrix.go }}\x64"'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
find-default-go:
|
|
||||||
name: 'Find default go version'
|
|
||||||
runs-on: windows-latest
|
|
||||||
outputs:
|
|
||||||
version: ${{ steps.goversion.outputs.version }}
|
|
||||||
steps:
|
|
||||||
- run: |
|
|
||||||
version=`go env GOVERSION|sed s/^go//`
|
|
||||||
echo "default go version: $version"
|
|
||||||
echo "version=$version" >> "$GITHUB_OUTPUT"
|
|
||||||
id: goversion
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
dont-create-link-if-default:
|
|
||||||
name: 'Validate if symlink is not created for default go'
|
|
||||||
runs-on: windows-latest
|
|
||||||
needs: find-default-go
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
cache: [false, true]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: 'Setup default go, cache: ${{ matrix.cache }}'
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: ${{ needs.find-default-go.outputs.version }}
|
|
||||||
cache: ${{ matrix.cache }}
|
|
||||||
|
|
||||||
- name: 'Drive C: should have Go installation, cache: ${{ matrix.cache}}'
|
|
||||||
run: |
|
|
||||||
size=$(du -m -s 'C:\hostedtoolcache\windows\go\${{ needs.find-default-go.outputs.version }}\x64'|cut -f1 -d$'\t')
|
|
||||||
if [ $size -eq 0 ];then
|
|
||||||
echo 'Size of the hosted go installed on drive c: must be above zero'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
- name: 'Drive D: should not have Go installation, cache: ${{ matrix.cache }}'
|
|
||||||
run: |
|
|
||||||
if [ -e 'D:\hostedtoolcache\windows\go\${{ needs.find-default-go.outputs.version }}\x64' ];then
|
|
||||||
echo 'D:\hostedtoolcache\windows\go\${{ needs.find-default-go.outputs.version }}\x64 should not exist for hosted version of go';
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
hostedtoolcache:
|
|
||||||
name: 'Validate if hostedtoolcache works as expected'
|
|
||||||
runs-on: windows-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
cache: [false]
|
|
||||||
go: [1.20.1]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: 'Setup ${{ matrix.go }}, cache: ${{ matrix.cache }}'
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go }}
|
|
||||||
cache: ${{ matrix.cache }}
|
|
||||||
|
|
||||||
- name: 'Setup ${{ matrix.go }}, cache: ${{ matrix.cache }} (from hostedtoolcache)'
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go }}
|
|
||||||
cache: ${{ matrix.cache }}
|
|
||||||
@ -13,4 +13,3 @@ allowed:
|
|||||||
|
|
||||||
reviewed:
|
reviewed:
|
||||||
npm:
|
npm:
|
||||||
- "@actions/http-client"
|
|
||||||
BIN
.licenses/npm/@actions/cache.dep.yml
generated
BIN
.licenses/npm/@actions/cache.dep.yml
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@actions/io-2.0.0.dep.yml
generated
BIN
.licenses/npm/@actions/io-2.0.0.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@actions/tool-cache.dep.yml
generated
BIN
.licenses/npm/@actions/tool-cache.dep.yml
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@azure/core-auth.dep.yml
generated
BIN
.licenses/npm/@azure/core-auth.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-client.dep.yml
generated
BIN
.licenses/npm/@azure/core-client.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-http-compat.dep.yml
generated
BIN
.licenses/npm/@azure/core-http-compat.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@azure/core-lro.dep.yml
generated
BIN
.licenses/npm/@azure/core-lro.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-paging.dep.yml
generated
BIN
.licenses/npm/@azure/core-paging.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-rest-pipeline.dep.yml
generated
BIN
.licenses/npm/@azure/core-rest-pipeline.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-tracing.dep.yml
generated
BIN
.licenses/npm/@azure/core-tracing.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-util.dep.yml
generated
BIN
.licenses/npm/@azure/core-util.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/core-xml.dep.yml
generated
BIN
.licenses/npm/@azure/core-xml.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/logger.dep.yml
generated
BIN
.licenses/npm/@azure/logger.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@azure/ms-rest-js.dep.yml
generated
Normal file
BIN
.licenses/npm/@azure/ms-rest-js.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/@azure/storage-blob.dep.yml
generated
BIN
.licenses/npm/@azure/storage-blob.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/@protobuf-ts/runtime.dep.yml
generated
BIN
.licenses/npm/@protobuf-ts/runtime.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@types/node-fetch.dep.yml
generated
Normal file
BIN
.licenses/npm/@types/node-fetch.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/@types/node.dep.yml
generated
Normal file
BIN
.licenses/npm/@types/node.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/@types/tunnel.dep.yml
generated
Normal file
BIN
.licenses/npm/@types/tunnel.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/@typespec/ts-http-runtime.dep.yml
generated
BIN
.licenses/npm/@typespec/ts-http-runtime.dep.yml
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/brace-expansion.dep.yml
generated
BIN
.licenses/npm/brace-expansion.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/debug.dep.yml
generated
BIN
.licenses/npm/debug.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/delayed-stream.dep.yml
generated
Normal file
BIN
.licenses/npm/delayed-stream.dep.yml
generated
Normal file
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/form-data-2.5.1.dep.yml
generated
Normal file
BIN
.licenses/npm/form-data-2.5.1.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/form-data-3.0.1.dep.yml
generated
Normal file
BIN
.licenses/npm/form-data-3.0.1.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/form-data-4.0.0.dep.yml
generated
Normal file
BIN
.licenses/npm/form-data-4.0.0.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/ip-regex.dep.yml
generated
Normal file
BIN
.licenses/npm/ip-regex.dep.yml
generated
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/minimatch.dep.yml
generated
BIN
.licenses/npm/minimatch.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/node-fetch.dep.yml
generated
Normal file
BIN
.licenses/npm/node-fetch.dep.yml
generated
Normal file
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/psl.dep.yml
generated
Normal file
BIN
.licenses/npm/psl.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/punycode.dep.yml
generated
Normal file
BIN
.licenses/npm/punycode.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/sax.dep.yml
generated
Normal file
BIN
.licenses/npm/sax.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/semver-7.7.3.dep.yml
generated
BIN
.licenses/npm/semver-7.7.3.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/tough-cookie-3.0.1.dep.yml
generated
Normal file
BIN
.licenses/npm/tough-cookie-3.0.1.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/tough-cookie-4.0.0.dep.yml
generated
Normal file
BIN
.licenses/npm/tough-cookie-4.0.0.dep.yml
generated
Normal file
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/tslib-1.14.1.dep.yml
generated
Normal file
BIN
.licenses/npm/tslib-1.14.1.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/tslib-2.3.1.dep.yml
generated
Normal file
BIN
.licenses/npm/tslib-2.3.1.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/tslib.dep.yml
generated
BIN
.licenses/npm/tslib.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/undici-6.23.0.dep.yml
generated
BIN
.licenses/npm/undici-6.23.0.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/universalify.dep.yml
generated
Normal file
BIN
.licenses/npm/universalify.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/uuid-3.4.0.dep.yml
generated
Normal file
BIN
.licenses/npm/uuid-3.4.0.dep.yml
generated
Normal file
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
Normal file
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
Normal file
Binary file not shown.
BIN
.licenses/npm/whatwg-url.dep.yml
generated
Normal file
BIN
.licenses/npm/whatwg-url.dep.yml
generated
Normal file
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
Normal file
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
Normal file
Binary file not shown.
@ -1,7 +0,0 @@
|
|||||||
# Ignore list
|
|
||||||
/*
|
|
||||||
|
|
||||||
# Do not ignore these folders:
|
|
||||||
!__tests__/
|
|
||||||
!.github/
|
|
||||||
!src/
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
// This is a reusable configuration file copied from https://github.com/actions/reusable-workflows/tree/main/reusable-configurations. Please don't make changes to this file as it's the subject of an automatic update.
|
|
||||||
module.exports = {
|
|
||||||
printWidth: 80,
|
|
||||||
tabWidth: 2,
|
|
||||||
useTabs: false,
|
|
||||||
semi: true,
|
|
||||||
singleQuote: true,
|
|
||||||
trailingComma: 'none',
|
|
||||||
bracketSpacing: false,
|
|
||||||
arrowParens: 'avoid'
|
|
||||||
};
|
|
||||||
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 80,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSpacing": false,
|
||||||
|
"arrowParens": "avoid",
|
||||||
|
"parser": "typescript"
|
||||||
|
}
|
||||||
286
README.md
286
README.md
@ -3,142 +3,222 @@
|
|||||||
[](https://github.com/actions/setup-go/actions/workflows/basic-validation.yml)
|
[](https://github.com/actions/setup-go/actions/workflows/basic-validation.yml)
|
||||||
[](https://github.com/actions/setup-go/actions/workflows/versions.yml)
|
[](https://github.com/actions/setup-go/actions/workflows/versions.yml)
|
||||||
|
|
||||||
This action sets up a Go environment for use in GitHub Actions by:
|
This action sets up a go environment for use in actions by:
|
||||||
|
|
||||||
- Optionally downloading and caching a version of Go by version and adding it to the PATH
|
- Optionally downloading and caching a version of Go by version and adding to `PATH`.
|
||||||
- Optionally caching Go modules and build outputs
|
- Registering problem matchers for error output.
|
||||||
- Registering problem matchers for error output
|
|
||||||
|
|
||||||
## Breaking changes in V6
|
# V3
|
||||||
|
|
||||||
The V6 edition of the action includes:
|
The V3 edition of the action offers:
|
||||||
- **Upgraded Node.js runtime from node20 to node24**
|
|
||||||
> Make sure your runner is on version v2.327.1 or later to ensure compatibility with this release. See [Release Notes](https://github.com/actions/runner/releases/tag/v2.327.1)
|
|
||||||
|
|
||||||
- **Go toolchain**
|
- Adds `GOBIN` to the `PATH`
|
||||||
- Supports both `go` and `toolchain` directives in `go.mod`. If the `toolchain` directive is present, its version is used; otherwise, the action falls back to the `go` directive.
|
- Proxy support
|
||||||
|
- Check latest version
|
||||||
|
- Caching packages dependencies
|
||||||
|
- stable and oldstable aliases
|
||||||
|
- Bug Fixes (including issues around version matching and semver)
|
||||||
|
|
||||||
- **Cache key update**
|
The action will first check the local cache for a version match. If a version is not found locally, it will pull it from the `main` branch of the [go-versions](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository. On miss or failure, it will fall back to downloading directly from [go dist](https://storage.googleapis.com/golang). To change the default behavior, please use the [check-latest input](#check-latest-version).
|
||||||
- By default, the cache key for Go modules is based on `go.mod`. To use `go.sum`, configure the `cache-dependency-path` input.
|
|
||||||
|
|
||||||
See full release notes on the [releases page](https://github.com/actions/setup-go/releases).
|
**Note:** The `setup-go` action uses executable binaries which are built by Golang side. The action does not build golang from source code.
|
||||||
|
|
||||||
## Usage
|
Matching by [semver spec](https://github.com/npm/node-semver):
|
||||||
|
|
||||||
See [action.yml](action.yml).
|
|
||||||
|
|
||||||
<!-- start usage -->
|
|
||||||
```yaml
|
|
||||||
- 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
|
|
||||||
# Note: if both go-version and go-version-file are provided, go-version takes precedence.
|
|
||||||
go-version-file: 'go.mod'
|
|
||||||
|
|
||||||
# Set this option if you want the action to check for the latest available version
|
|
||||||
# Default: false
|
|
||||||
check-latest: false
|
|
||||||
|
|
||||||
# GitHub token for authentication
|
|
||||||
token: ${{ github.token }}
|
|
||||||
|
|
||||||
# Used to specify whether caching is needed.
|
|
||||||
# Default: true
|
|
||||||
cache: true
|
|
||||||
|
|
||||||
# Path to dependency files for caching
|
|
||||||
cache-dependency-path: 'go.sum'
|
|
||||||
|
|
||||||
# Architecture to install (auto-detected if not specified)
|
|
||||||
architecture: 'x64'
|
|
||||||
```
|
|
||||||
<!-- end usage -->
|
|
||||||
|
|
||||||
**Basic:**
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v6
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '1.25' # The Go version to download (if necessary) and use.
|
go-version: '^1.13.1' # The Go version to download (if necessary) and use.
|
||||||
|
- run: go version
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '>=1.17.0'
|
||||||
|
- run: go version
|
||||||
|
```
|
||||||
|
|
||||||
|
Matching an unstable pre-release:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.18.0-rc.1' # The Go version to download (if necessary) and use.
|
||||||
|
- run: go version
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.16.0-beta.1' # The Go version to download (if necessary) and use.
|
||||||
|
- run: go version
|
||||||
|
```
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
See [action.yml](action.yml)
|
||||||
|
|
||||||
|
## Basic
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.16.1' # The Go version to download (if necessary) and use.
|
||||||
- run: go run hello.go
|
- run: go run hello.go
|
||||||
```
|
```
|
||||||
|
|
||||||
**Version resolution behavior:**
|
|
||||||
|
|
||||||
The action resolves the requested version in the following order:
|
## Check latest version
|
||||||
1. **Local cache** - Checks the local tool cache for a matching [semver](https://github.com/npm/node-semver#versions) version.
|
|
||||||
2. **go-versions repository** - If the requested version isn’t available in the tool cache, it pulls the version manifest from the `main` branch of the [go-versions repository](https://github.com/actions/go-versions/blob/main/versions-manifest.json).
|
|
||||||
3. **Direct download** - If that lookup misses or fails, it will fall back to downloading directly from the [official Go distribution site](https://go.dev/dl).
|
|
||||||
|
|
||||||
To change the default behavior, please use
|
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific Go version is always used.
|
||||||
the [check-latest input](docs/advanced-usage.md#check-latest-version).
|
|
||||||
|
|
||||||
> **Note**: The `setup-go` action uses executable binaries built by the Go team and does not build Go binaries from source code.
|
If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally cached version is not the most up-to-date, a Go version will then be downloaded. Set `check-latest` to `true` if you want the most up-to-date Go version to always be used.
|
||||||
|
|
||||||
## Supported version syntax
|
> Setting `check-latest` to `true` has performance implications as downloading Go versions is slower than using cached versions.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.14'
|
||||||
|
check-latest: true
|
||||||
|
- run: go run hello.go
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using stable/oldstable aliases
|
||||||
|
|
||||||
|
If `stable` is provided, action will get the latest stable version from the [`go-versions`](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository manifest.
|
||||||
|
|
||||||
|
If `oldstable` is provided, when current release is 1.19.x, action will resolve version as 1.18.x, where x is the latest patch release.
|
||||||
|
|
||||||
|
**Note:** using these aliases will result in same version as using corresponding minor release with `check-latest` input set to `true`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 'stable'
|
||||||
|
- run: go run hello.go
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 'oldstable'
|
||||||
|
- run: go run hello.go
|
||||||
|
```
|
||||||
|
|
||||||
|
## Caching dependency files and build outputs:
|
||||||
|
|
||||||
|
The action has a built-in functionality for caching and restoring go modules and build outputs. It uses [actions/cache](https://github.com/actions/cache) under the hood but requires less configuration settings. The `cache` input is optional, and caching is turned off by default.
|
||||||
|
|
||||||
|
The action defaults to search for the dependency file - go.sum in the repository root, and uses its hash as a part of the cache key. Use `cache-dependency-path` input for cases when multiple dependency files are used, or they are located in different subdirectories.
|
||||||
|
|
||||||
|
**Caching without specifying dependency file path**
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.17'
|
||||||
|
check-latest: true
|
||||||
|
cache: true
|
||||||
|
- run: go run hello.go
|
||||||
|
```
|
||||||
|
|
||||||
|
**Caching in monorepos**
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '1.17'
|
||||||
|
check-latest: true
|
||||||
|
cache: true
|
||||||
|
cache-dependency-path: subdir/go.sum
|
||||||
|
- run: go run hello.go
|
||||||
|
```
|
||||||
|
## Getting go version from the go.mod file
|
||||||
|
|
||||||
|
The `go-version-file` input accepts a path to a `go.mod` file or a `go.work` file that contains the version of Go to be used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version sequentially in the runner's directory with the cached tools, in the [versions-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers.
|
||||||
|
|
||||||
|
If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used.
|
||||||
|
> The action will search for the `go.mod` file relative to the repository root
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version-file: 'path/to/go.mod'
|
||||||
|
- run: go version
|
||||||
|
```
|
||||||
|
|
||||||
|
## Matrix testing
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go: [ '1.14', '1.13' ]
|
||||||
|
name: Go ${{ matrix.go }} sample
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Setup go
|
||||||
|
uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go }}
|
||||||
|
- run: go run hello.go
|
||||||
|
```
|
||||||
|
|
||||||
|
### Supported version syntax
|
||||||
|
|
||||||
The `go-version` input supports the following syntax:
|
The `go-version` input supports the following syntax:
|
||||||
|
|
||||||
- Specific versions: `1.25`, `1.24.11`, `1.24.0-rc.1`, `1.23.0-beta.1`
|
- Specific versions: `1.15`, `1.16.1`, `1.17.0-rc.2`, `1.16.0-beta.1`
|
||||||
- SemVer version range syntax: `^1.25.1`, `~1.24.1`, `>=1.25.0-rc.1`, `<1.25.0`, `>=1.22.0 <1.24.0`
|
- SemVer's version range syntax: `^1.13.1`, `>=1.18.0-rc.1`
|
||||||
- Aliases: `stable`, `oldstable`
|
|
||||||
- Wildcards: `1.25.x`, `1.x`
|
|
||||||
|
|
||||||
For details on Semantic Versioning, see [the semver package documentation](https://github.com/npm/node-semver).
|
For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver) documentation.
|
||||||
|
|
||||||
> **Note**: Due to the peculiarities of YAML parsing, it is recommended to wrap the version in single quotation marks:
|
## Using `setup-go` on GHES
|
||||||
>
|
|
||||||
> ```yaml
|
|
||||||
> go-version: '1.20'
|
|
||||||
> ```
|
|
||||||
>
|
|
||||||
> The recommendation is based on the YAML parser's behavior, which interprets non-wrapped values as numbers and, in the case of version `1.20`, trims it down to `1.2`, which may not be very obvious.
|
|
||||||
|
|
||||||
For more usage examples, please refer to the section: [Using go-version input](docs/advanced-usage.md#using-the-go-version-input) of the [Advanced usage](docs/advanced-usage.md) guide.
|
`setup-go` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading Go distributions, `setup-go` downloads distributions from [`actions/go-versions`](https://github.com/actions/go-versions) on github.com (outside of the appliance). These calls to `actions/go-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting). If more requests are made within the time frame, then you will start to see rate-limit errors during downloading that looks like: `##[error]API rate limit exceeded for...`. After that error the action will try to download versions directly from https://storage.googleapis.com/golang, but it also can have rate limit so it's better to put token.
|
||||||
|
|
||||||
## Recommended permissions
|
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new) and pass it as the `token` input for the action:
|
||||||
|
|
||||||
When using the `setup-go` action in your GitHub Actions workflow, it is recommended to set the following permissions to ensure proper functionality:
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
permissions:
|
uses: actions/setup-go@v3
|
||||||
contents: read # access to check out code and install dependencies
|
with:
|
||||||
|
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
||||||
|
go-version: 1.18
|
||||||
```
|
```
|
||||||
|
|
||||||
## Caching dependency files and build outputs
|
If the runner is not able to access github.com, any Go versions requested during a workflow run must come from the runner's tool cache. See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)" for more information.
|
||||||
|
|
||||||
The action includes built-in caching and restoration for Go modules and build outputs. It uses
|
# License
|
||||||
[toolkit/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood, but requires less configuration.
|
|
||||||
The `cache` input is optional, and caching is enabled by default. To disable caching, set `cache: false`.
|
|
||||||
|
|
||||||
By default, the action looks for `go.mod` in the repository root and uses its hash as part of the cache key. Use the `cache-dependency-path` input when you have multiple dependency files, or when they’re located in different subdirectories. This input supports glob patterns.
|
The scripts and documentation in this project are released under the [MIT License](LICENSE)
|
||||||
|
|
||||||
If caching cannot be performed for any reason, the action logs a warning and continues workflow execution.
|
# Contributions
|
||||||
|
|
||||||
For examples of using `cache-dependency-path`, see the [Caching](docs/advanced-usage.md#caching) section of the [Advanced usage](docs/advanced-usage.md) guide.
|
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
||||||
|
|
||||||
|
|
||||||
## Advanced usage
|
|
||||||
|
|
||||||
- [Using the go-version input](docs/advanced-usage.md#using-the-go-version-input)
|
|
||||||
- [Using the go-version-file input](docs/advanced-usage.md#using-the-go-version-file-input)
|
|
||||||
- [Check latest version](docs/advanced-usage.md#check-latest-version)
|
|
||||||
- [Caching](docs/advanced-usage.md#caching)
|
|
||||||
- [Outputs](docs/advanced-usage.md#outputs)
|
|
||||||
- [Using `setup-go` on GHES](docs/advanced-usage.md#using-setup-go-on-ghes)
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
The scripts and documentation in this project are released under the [MIT License](LICENSE).
|
|
||||||
|
|
||||||
## Contributions
|
|
||||||
|
|
||||||
Contributions are welcome! See our [Contributor's Guide](docs/contributors.md).
|
|
||||||
|
|
||||||
## Code of Conduct
|
## Code of Conduct
|
||||||
|
|
||||||
|
|||||||
@ -1,102 +1,99 @@
|
|||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
import fs from 'fs';
|
|
||||||
|
|
||||||
import * as cacheRestore from '../src/cache-restore';
|
import * as cacheRestore from '../src/cache-restore';
|
||||||
import * as cacheUtils from '../src/cache-utils';
|
import * as cacheUtils from '../src/cache-utils';
|
||||||
import {PackageManagerInfo} from '../src/package-managers';
|
import {PackageManagerInfo} from '../src/package-managers';
|
||||||
|
|
||||||
describe('restoreCache', () => {
|
describe('restoreCache', () => {
|
||||||
let hashFilesSpy: jest.SpyInstance;
|
//Arrange
|
||||||
let getCacheDirectoryPathSpy: jest.SpyInstance;
|
let hashFilesSpy = jest.spyOn(glob, 'hashFiles');
|
||||||
let restoreCacheSpy: jest.SpyInstance;
|
let getCacheDirectoryPathSpy = jest.spyOn(
|
||||||
let infoSpy: jest.SpyInstance;
|
cacheUtils,
|
||||||
let setOutputSpy: jest.SpyInstance;
|
'getCacheDirectoryPath'
|
||||||
|
);
|
||||||
|
let restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
|
||||||
|
let infoSpy = jest.spyOn(core, 'info');
|
||||||
|
let setOutputSpy = jest.spyOn(core, 'setOutput');
|
||||||
|
|
||||||
const versionSpec = '1.13.1';
|
const versionSpec = '1.13.1';
|
||||||
const packageManager = 'default';
|
const packageManager = 'default';
|
||||||
const cacheDependencyPath = 'path';
|
const cacheDependencyPath = 'path';
|
||||||
|
|
||||||
let originalWorkspace: string | undefined;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
originalWorkspace = process.env.GITHUB_WORKSPACE;
|
|
||||||
process.env.GITHUB_WORKSPACE = '/test/workspace';
|
|
||||||
//Arrange
|
|
||||||
hashFilesSpy = jest.spyOn(glob, 'hashFiles');
|
|
||||||
getCacheDirectoryPathSpy = jest.spyOn(cacheUtils, 'getCacheDirectoryPath');
|
|
||||||
restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
|
|
||||||
infoSpy = jest.spyOn(core, 'info');
|
|
||||||
setOutputSpy = jest.spyOn(core, 'setOutput');
|
|
||||||
|
|
||||||
getCacheDirectoryPathSpy.mockImplementation(
|
getCacheDirectoryPathSpy.mockImplementation(
|
||||||
(PackageManager: PackageManagerInfo) => {
|
(PackageManager: PackageManagerInfo) => {
|
||||||
return Promise.resolve([
|
return new Promise<string[]>(resolve => {
|
||||||
'cache_directory_path',
|
resolve(['cache_directory_path', 'cache_directory_path']);
|
||||||
'cache_directory_path'
|
});
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
process.env.GITHUB_WORKSPACE = originalWorkspace;
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw if dependency file path is not valid', async () => {
|
it('should throw if dependency file path is not valid', async () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
hashFilesSpy.mockImplementation(() => Promise.resolve(''));
|
hashFilesSpy.mockImplementation((somePath: string) => {
|
||||||
|
return new Promise<string>(resolve => {
|
||||||
|
resolve('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
await expect(
|
expect(async () => {
|
||||||
cacheRestore.restoreCache(
|
await cacheRestore.restoreCache(
|
||||||
versionSpec,
|
versionSpec,
|
||||||
packageManager,
|
packageManager,
|
||||||
cacheDependencyPath
|
cacheDependencyPath
|
||||||
)
|
);
|
||||||
).rejects.toThrow(
|
}).rejects.toThrowError(
|
||||||
'Some specified paths were not resolved, unable to cache dependencies.'
|
'Some specified paths were not resolved, unable to cache dependencies.'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should inform if cache hit is not occurred', async () => {
|
it('should inform if cache hit is not occured', async () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
hashFilesSpy.mockImplementation(() => Promise.resolve('file_hash'));
|
hashFilesSpy.mockImplementation((somePath: string) => {
|
||||||
restoreCacheSpy.mockImplementation(() => Promise.resolve(''));
|
return new Promise<string>(resolve => {
|
||||||
|
resolve('file_hash');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
restoreCacheSpy.mockImplementation(() => {
|
||||||
|
return new Promise<string>(resolve => {
|
||||||
|
resolve('');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
await cacheRestore.restoreCache(
|
await cacheRestore.restoreCache(
|
||||||
versionSpec,
|
versionSpec,
|
||||||
packageManager,
|
packageManager,
|
||||||
cacheDependencyPath
|
cacheDependencyPath
|
||||||
);
|
);
|
||||||
expect(infoSpy).toHaveBeenCalledWith('Cache is not found');
|
expect(infoSpy).toBeCalledWith(`Cache is not found`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set output if cache hit is occurred', async () => {
|
it('should set output if cache hit is occured', async () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
hashFilesSpy.mockImplementation(() => Promise.resolve('file_hash'));
|
hashFilesSpy.mockImplementation((somePath: string) => {
|
||||||
restoreCacheSpy.mockImplementation(() => Promise.resolve('cache_key'));
|
return new Promise<string>(resolve => {
|
||||||
|
resolve('file_hash');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
restoreCacheSpy.mockImplementation(() => {
|
||||||
|
return new Promise<string>(resolve => {
|
||||||
|
resolve('cache_key');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
await cacheRestore.restoreCache(
|
await cacheRestore.restoreCache(
|
||||||
versionSpec,
|
versionSpec,
|
||||||
packageManager,
|
packageManager,
|
||||||
cacheDependencyPath
|
cacheDependencyPath
|
||||||
);
|
);
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
|
expect(setOutputSpy).toBeCalledWith('cache-hit', true);
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw if dependency file is not found in workspace', async () => {
|
|
||||||
jest.spyOn(fs, 'readdirSync').mockReturnValue(['main.go'] as any);
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
cacheRestore.restoreCache(
|
|
||||||
versionSpec,
|
|
||||||
packageManager
|
|
||||||
// No cacheDependencyPath
|
|
||||||
)
|
|
||||||
).rejects.toThrow(
|
|
||||||
'Dependencies file is not found in /test/workspace. Supported file pattern: go.mod'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {PackageManagerInfo} from '../src/package-managers';
|
|||||||
|
|
||||||
describe('getCommandOutput', () => {
|
describe('getCommandOutput', () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
let getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
||||||
|
|
||||||
it('should return trimmed stdout in case of successful exit code', async () => {
|
it('should return trimmed stdout in case of successful exit code', async () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
@ -36,7 +36,7 @@ describe('getCommandOutput', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
await expect(async () => {
|
expect(async () => {
|
||||||
await cacheUtils.getCommandOutput('command');
|
await cacheUtils.getCommandOutput('command');
|
||||||
}).rejects.toThrow();
|
}).rejects.toThrow();
|
||||||
});
|
});
|
||||||
@ -47,7 +47,7 @@ describe('getPackageManagerInfo', () => {
|
|||||||
//Arrange
|
//Arrange
|
||||||
const packageManagerName = 'default';
|
const packageManagerName = 'default';
|
||||||
const expectedResult = {
|
const expectedResult = {
|
||||||
dependencyFilePattern: 'go.mod',
|
dependencyFilePattern: 'go.sum',
|
||||||
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ describe('getPackageManagerInfo', () => {
|
|||||||
const packageManagerName = 'invalidName';
|
const packageManagerName = 'invalidName';
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
await expect(async () => {
|
expect(async () => {
|
||||||
await cacheUtils.getPackageManagerInfo(packageManagerName);
|
await cacheUtils.getPackageManagerInfo(packageManagerName);
|
||||||
}).rejects.toThrow();
|
}).rejects.toThrow();
|
||||||
});
|
});
|
||||||
@ -70,10 +70,10 @@ describe('getPackageManagerInfo', () => {
|
|||||||
|
|
||||||
describe('getCacheDirectoryPath', () => {
|
describe('getCacheDirectoryPath', () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
let getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
||||||
|
|
||||||
const validPackageManager: PackageManagerInfo = {
|
const validPackageManager: PackageManagerInfo = {
|
||||||
dependencyFilePattern: 'go.mod',
|
dependencyFilePattern: 'go.sum',
|
||||||
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ describe('getCacheDirectoryPath', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
await expect(async () => {
|
expect(async () => {
|
||||||
await cacheUtils.getCacheDirectoryPath(validPackageManager);
|
await cacheUtils.getCacheDirectoryPath(validPackageManager);
|
||||||
}).rejects.toThrow();
|
}).rejects.toThrow();
|
||||||
});
|
});
|
||||||
@ -136,7 +136,7 @@ describe('getCacheDirectoryPath', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
await expect(async () => {
|
expect(async () => {
|
||||||
await cacheUtils.getCacheDirectoryPath(validPackageManager);
|
await cacheUtils.getCacheDirectoryPath(validPackageManager);
|
||||||
}).rejects.toThrow();
|
}).rejects.toThrow();
|
||||||
});
|
});
|
||||||
@ -144,8 +144,8 @@ describe('getCacheDirectoryPath', () => {
|
|||||||
|
|
||||||
describe('isCacheFeatureAvailable', () => {
|
describe('isCacheFeatureAvailable', () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
const isFeatureAvailableSpy = jest.spyOn(cache, 'isFeatureAvailable');
|
let isFeatureAvailableSpy = jest.spyOn(cache, 'isFeatureAvailable');
|
||||||
const warningSpy = jest.spyOn(core, 'warning');
|
let warningSpy = jest.spyOn(core, 'warning');
|
||||||
|
|
||||||
it('should return true when cache feature is available', () => {
|
it('should return true when cache feature is available', () => {
|
||||||
//Arrange
|
//Arrange
|
||||||
@ -153,8 +153,10 @@ describe('isCacheFeatureAvailable', () => {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let functionResult;
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
const functionResult = cacheUtils.isCacheFeatureAvailable();
|
functionResult = cacheUtils.isCacheFeatureAvailable();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
expect(functionResult).toBeTruthy();
|
expect(functionResult).toBeTruthy();
|
||||||
@ -168,7 +170,7 @@ describe('isCacheFeatureAvailable', () => {
|
|||||||
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
|
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
|
||||||
|
|
||||||
const warningMessage =
|
let warningMessage =
|
||||||
'The runner was not able to contact the cache service. Caching will be skipped';
|
'The runner was not able to contact the cache service. Caching will be skipped';
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
@ -186,8 +188,10 @@ describe('isCacheFeatureAvailable', () => {
|
|||||||
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
|
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
|
||||||
|
|
||||||
|
let functionResult;
|
||||||
|
|
||||||
//Act
|
//Act
|
||||||
const functionResult = cacheUtils.isCacheFeatureAvailable();
|
functionResult = cacheUtils.isCacheFeatureAvailable();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
expect(functionResult).toBeFalsy();
|
expect(functionResult).toBeFalsy();
|
||||||
@ -201,7 +205,7 @@ describe('isCacheFeatureAvailable', () => {
|
|||||||
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://nongithub.com';
|
process.env['GITHUB_SERVER_URL'] = 'https://nongithub.com';
|
||||||
|
|
||||||
const warningMessage =
|
let warningMessage =
|
||||||
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.';
|
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.';
|
||||||
|
|
||||||
//Act + Assert
|
//Act + Assert
|
||||||
@ -209,41 +213,3 @@ describe('isCacheFeatureAvailable', () => {
|
|||||||
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
|
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('isGhes', () => {
|
|
||||||
const pristineEnv = process.env;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.resetModules();
|
|
||||||
process.env = {...pristineEnv};
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
process.env = pristineEnv;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns false when the GITHUB_SERVER_URL environment variable is not defined', async () => {
|
|
||||||
delete process.env['GITHUB_SERVER_URL'];
|
|
||||||
expect(cacheUtils.isGhes()).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns false when the GITHUB_SERVER_URL environment variable is set to github.com', async () => {
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
|
|
||||||
expect(cacheUtils.isGhes()).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL', async () => {
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://contoso.ghe.com';
|
|
||||||
expect(cacheUtils.isGhes()).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix', async () => {
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://mock-github.localhost';
|
|
||||||
expect(cacheUtils.isGhes()).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('returns true when the GITHUB_SERVER_URL environment variable is set to some other URL', async () => {
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://src.onpremise.fabrikam.com';
|
|
||||||
expect(cacheUtils.isGhes()).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
1.22.4
|
|
||||||
@ -1 +0,0 @@
|
|||||||
golang 1.23.2
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
module example.com/mymodule
|
module example.com/mymodule
|
||||||
|
|
||||||
go 1.20
|
go 1.14
|
||||||
|
|
||||||
require (
|
require (
|
||||||
example.com/othermodule v1.2.3
|
example.com/othermodule v1.2.3
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
go 1.21
|
go 1.19
|
||||||
|
|
||||||
use .
|
use .
|
||||||
|
|||||||
@ -3,21 +3,18 @@ import * as io from '@actions/io';
|
|||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import cp from 'child_process';
|
import cp from 'child_process';
|
||||||
import osm, {type} from 'os';
|
import osm from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as main from '../src/main';
|
import * as main from '../src/main';
|
||||||
import * as im from '../src/installer';
|
import * as im from '../src/installer';
|
||||||
import * as httpm from '@actions/http-client';
|
|
||||||
|
|
||||||
import goJsonData from './data/golang-dl.json';
|
let goJsonData = require('./data/golang-dl.json');
|
||||||
import matchers from '../matchers.json';
|
let matchers = require('../matchers.json');
|
||||||
import goTestManifest from './data/versions-manifest.json';
|
let goTestManifest = require('./data/versions-manifest.json');
|
||||||
const matcherPattern = matchers.problemMatcher[0].pattern[0];
|
let matcherPattern = matchers.problemMatcher[0].pattern[0];
|
||||||
const matcherRegExp = new RegExp(matcherPattern.regexp);
|
let matcherRegExp = new RegExp(matcherPattern.regexp);
|
||||||
const win32Join = path.win32.join;
|
let win32Join = path.win32.join;
|
||||||
const posixJoin = path.posix.join;
|
let posixJoin = path.posix.join;
|
||||||
|
|
||||||
jest.setTimeout(10000);
|
|
||||||
|
|
||||||
describe('setup-go', () => {
|
describe('setup-go', () => {
|
||||||
let inputs = {} as any;
|
let inputs = {} as any;
|
||||||
@ -42,12 +39,9 @@ describe('setup-go', () => {
|
|||||||
let existsSpy: jest.SpyInstance;
|
let existsSpy: jest.SpyInstance;
|
||||||
let readFileSpy: jest.SpyInstance;
|
let readFileSpy: jest.SpyInstance;
|
||||||
let mkdirpSpy: jest.SpyInstance;
|
let mkdirpSpy: jest.SpyInstance;
|
||||||
let mkdirSpy: jest.SpyInstance;
|
|
||||||
let symlinkSpy: jest.SpyInstance;
|
|
||||||
let execSpy: jest.SpyInstance;
|
let execSpy: jest.SpyInstance;
|
||||||
let getManifestSpy: jest.SpyInstance;
|
let getManifestSpy: jest.SpyInstance;
|
||||||
let getAllVersionsSpy: jest.SpyInstance;
|
let getAllVersionsSpy: jest.SpyInstance;
|
||||||
let httpmGetJsonSpy: jest.SpyInstance;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
|
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
|
||||||
@ -92,20 +86,12 @@ describe('setup-go', () => {
|
|||||||
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
|
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
|
||||||
getAllVersionsSpy = jest.spyOn(im, 'getManifest');
|
getAllVersionsSpy = jest.spyOn(im, 'getManifest');
|
||||||
|
|
||||||
// httm
|
|
||||||
httpmGetJsonSpy = jest.spyOn(httpm.HttpClient.prototype, 'getJson');
|
|
||||||
|
|
||||||
// io
|
// io
|
||||||
whichSpy = jest.spyOn(io, 'which');
|
whichSpy = jest.spyOn(io, 'which');
|
||||||
existsSpy = jest.spyOn(fs, 'existsSync');
|
existsSpy = jest.spyOn(fs, 'existsSync');
|
||||||
readFileSpy = jest.spyOn(fs, 'readFileSync');
|
readFileSpy = jest.spyOn(fs, 'readFileSync');
|
||||||
mkdirpSpy = jest.spyOn(io, 'mkdirP');
|
mkdirpSpy = jest.spyOn(io, 'mkdirP');
|
||||||
|
|
||||||
// fs
|
|
||||||
mkdirSpy = jest.spyOn(fs, 'mkdir');
|
|
||||||
symlinkSpy = jest.spyOn(fs, 'symlinkSync');
|
|
||||||
symlinkSpy.mockImplementation(() => {});
|
|
||||||
|
|
||||||
// gets
|
// gets
|
||||||
getManifestSpy.mockImplementation(() => <tc.IToolRelease[]>goTestManifest);
|
getManifestSpy.mockImplementation(() => <tc.IToolRelease[]>goTestManifest);
|
||||||
|
|
||||||
@ -129,9 +115,6 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
// clear out env var set during 'run'
|
|
||||||
delete process.env[im.GOTOOLCHAIN_ENV_VAR];
|
|
||||||
|
|
||||||
//jest.resetAllMocks();
|
//jest.resetAllMocks();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
//jest.restoreAllMocks();
|
//jest.restoreAllMocks();
|
||||||
@ -150,7 +133,7 @@ describe('setup-go', () => {
|
|||||||
os.platform = 'darwin';
|
os.platform = 'darwin';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken');
|
let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken');
|
||||||
expect(match).toBeDefined();
|
expect(match).toBeDefined();
|
||||||
expect(match!.resolvedVersion).toBe('1.9.7');
|
expect(match!.resolvedVersion).toBe('1.9.7');
|
||||||
expect(match!.type).toBe('manifest');
|
expect(match!.type).toBe('manifest');
|
||||||
@ -159,26 +142,11 @@ describe('setup-go', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return manifest from repo', async () => {
|
|
||||||
const manifest = await im.getManifest(undefined);
|
|
||||||
expect(manifest).toEqual(goTestManifest);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return manifest from raw URL if repo fetch fails', async () => {
|
|
||||||
getManifestSpy.mockRejectedValue(new Error('Fetch failed'));
|
|
||||||
httpmGetJsonSpy.mockResolvedValue({
|
|
||||||
result: goTestManifest
|
|
||||||
});
|
|
||||||
const manifest = await im.getManifest(undefined);
|
|
||||||
expect(httpmGetJsonSpy).toHaveBeenCalled();
|
|
||||||
expect(manifest).toEqual(goTestManifest);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can find 1.9 from manifest on linux', async () => {
|
it('can find 1.9 from manifest on linux', async () => {
|
||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken');
|
let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken');
|
||||||
expect(match).toBeDefined();
|
expect(match).toBeDefined();
|
||||||
expect(match!.resolvedVersion).toBe('1.9.7');
|
expect(match!.resolvedVersion).toBe('1.9.7');
|
||||||
expect(match!.type).toBe('manifest');
|
expect(match!.type).toBe('manifest');
|
||||||
@ -191,7 +159,7 @@ describe('setup-go', () => {
|
|||||||
os.platform = 'win32';
|
os.platform = 'win32';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken');
|
let match = await im.getInfoFromManifest('1.9.7', true, 'mocktoken');
|
||||||
expect(match).toBeDefined();
|
expect(match).toBeDefined();
|
||||||
expect(match!.resolvedVersion).toBe('1.9.7');
|
expect(match!.resolvedVersion).toBe('1.9.7');
|
||||||
expect(match!.type).toBe('manifest');
|
expect(match!.type).toBe('manifest');
|
||||||
@ -205,11 +173,11 @@ describe('setup-go', () => {
|
|||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
// spec: 1.13.0 => 1.13
|
// spec: 1.13.0 => 1.13
|
||||||
const match: im.IGoVersion | undefined = await im.findMatch('1.13.0');
|
let match: im.IGoVersion | undefined = await im.findMatch('1.13.0');
|
||||||
expect(match).toBeDefined();
|
expect(match).toBeDefined();
|
||||||
const version: string = match ? match.version : '';
|
let version: string = match ? match.version : '';
|
||||||
expect(version).toBe('go1.13');
|
expect(version).toBe('go1.13');
|
||||||
const fileName = match ? match.files[0].filename : '';
|
let fileName = match ? match.files[0].filename : '';
|
||||||
expect(fileName).toBe('go1.13.darwin-amd64.tar.gz');
|
expect(fileName).toBe('go1.13.darwin-amd64.tar.gz');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -218,11 +186,11 @@ describe('setup-go', () => {
|
|||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
// spec: 1.13 => 1.13.7 (latest)
|
// spec: 1.13 => 1.13.7 (latest)
|
||||||
const match: im.IGoVersion | undefined = await im.findMatch('1.13');
|
let match: im.IGoVersion | undefined = await im.findMatch('1.13');
|
||||||
expect(match).toBeDefined();
|
expect(match).toBeDefined();
|
||||||
const version: string = match ? match.version : '';
|
let version: string = match ? match.version : '';
|
||||||
expect(version).toBe('go1.13.7');
|
expect(version).toBe('go1.13.7');
|
||||||
const fileName = match ? match.files[0].filename : '';
|
let fileName = match ? match.files[0].filename : '';
|
||||||
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
|
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -231,11 +199,11 @@ describe('setup-go', () => {
|
|||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
// spec: ^1.13.6 => 1.13.7
|
// spec: ^1.13.6 => 1.13.7
|
||||||
const match: im.IGoVersion | undefined = await im.findMatch('^1.13.6');
|
let match: im.IGoVersion | undefined = await im.findMatch('^1.13.6');
|
||||||
expect(match).toBeDefined();
|
expect(match).toBeDefined();
|
||||||
const version: string = match ? match.version : '';
|
let version: string = match ? match.version : '';
|
||||||
expect(version).toBe('go1.13.7');
|
expect(version).toBe('go1.13.7');
|
||||||
const fileName = match ? match.files[0].filename : '';
|
let fileName = match ? match.files[0].filename : '';
|
||||||
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
|
expect(fileName).toBe('go1.13.7.linux-amd64.tar.gz');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -244,11 +212,11 @@ describe('setup-go', () => {
|
|||||||
os.arch = 'x32';
|
os.arch = 'x32';
|
||||||
|
|
||||||
// spec: 1 => 1.13.7 (latest)
|
// spec: 1 => 1.13.7 (latest)
|
||||||
const match: im.IGoVersion | undefined = await im.findMatch('1');
|
let match: im.IGoVersion | undefined = await im.findMatch('1');
|
||||||
expect(match).toBeDefined();
|
expect(match).toBeDefined();
|
||||||
const version: string = match ? match.version : '';
|
let version: string = match ? match.version : '';
|
||||||
expect(version).toBe('go1.13.7');
|
expect(version).toBe('go1.13.7');
|
||||||
const fileName = match ? match.files[0].filename : '';
|
let fileName = match ? match.files[0].filename : '';
|
||||||
expect(fileName).toBe('go1.13.7.windows-386.zip');
|
expect(fileName).toBe('go1.13.7.windows-386.zip');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -257,11 +225,11 @@ describe('setup-go', () => {
|
|||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
// spec: 1.14, stable=false => go1.14rc1
|
// spec: 1.14, stable=false => go1.14rc1
|
||||||
const match: im.IGoVersion | undefined = await im.findMatch('1.14.0-rc.1');
|
let match: im.IGoVersion | undefined = await im.findMatch('1.14.0-rc.1');
|
||||||
expect(match).toBeDefined();
|
expect(match).toBeDefined();
|
||||||
const version: string = match ? match.version : '';
|
let version: string = match ? match.version : '';
|
||||||
expect(version).toBe('go1.14rc1');
|
expect(version).toBe('go1.14rc1');
|
||||||
const fileName = match ? match.files[0].filename : '';
|
let fileName = match ? match.files[0].filename : '';
|
||||||
expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz');
|
expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -269,7 +237,7 @@ describe('setup-go', () => {
|
|||||||
inputs['go-version'] = '1.13.0';
|
inputs['go-version'] = '1.13.0';
|
||||||
inputs.stable = 'true';
|
inputs.stable = 'true';
|
||||||
|
|
||||||
const toolPath = path.normalize('/cache/go/1.13.0/x64');
|
let toolPath = path.normalize('/cache/go/1.13.0/x64');
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
@ -281,49 +249,51 @@ describe('setup-go', () => {
|
|||||||
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
|
|
||||||
const toolPath = path.normalize('/cache/go/1.13.0/x64');
|
let toolPath = path.normalize('/cache/go/1.13.0/x64');
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`);
|
expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not export GOROOT for Go versions >=1.9', async () => {
|
it('does not export any variables for Go versions >=1.9', async () => {
|
||||||
inputs['go-version'] = '1.13.0';
|
inputs['go-version'] = '1.13.0';
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
|
|
||||||
const toolPath = path.normalize('/cache/go/1.13.0/x64');
|
let toolPath = path.normalize('/cache/go/1.13.0/x64');
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
|
|
||||||
const vars: {[key: string]: string} = {};
|
let vars: {[key: string]: string} = {};
|
||||||
exportVarSpy.mockImplementation((name: string, val: string) => {
|
exportVarSpy.mockImplementation((name: string, val: string) => {
|
||||||
vars[name] = val;
|
vars[name] = val;
|
||||||
});
|
});
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
expect(vars).not.toHaveProperty('GOROOT');
|
expect(vars).toStrictEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('exports GOROOT for Go versions <1.9', async () => {
|
it('exports GOROOT for Go versions <1.9', async () => {
|
||||||
inputs['go-version'] = '1.8';
|
inputs['go-version'] = '1.8';
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
|
|
||||||
const toolPath = path.normalize('/cache/go/1.8.0/x64');
|
let toolPath = path.normalize('/cache/go/1.8.0/x64');
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
|
|
||||||
const vars: {[key: string]: string} = {};
|
let vars: {[key: string]: string} = {};
|
||||||
exportVarSpy.mockImplementation((name: string, val: string) => {
|
exportVarSpy.mockImplementation((name: string, val: string) => {
|
||||||
vars[name] = val;
|
vars[name] = val;
|
||||||
});
|
});
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
expect(vars).toHaveProperty('GOROOT', toolPath);
|
expect(vars).toStrictEqual({
|
||||||
|
GOROOT: toolPath
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('finds a version of go already in the cache', async () => {
|
it('finds a version of go already in the cache', async () => {
|
||||||
inputs['go-version'] = '1.13.0';
|
inputs['go-version'] = '1.13.0';
|
||||||
|
|
||||||
const toolPath = path.normalize('/cache/go/1.13.0/x64');
|
let toolPath = path.normalize('/cache/go/1.13.0/x64');
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
@ -332,16 +302,16 @@ describe('setup-go', () => {
|
|||||||
|
|
||||||
it('finds a version in the cache and adds it to the path', async () => {
|
it('finds a version in the cache and adds it to the path', async () => {
|
||||||
inputs['go-version'] = '1.13.0';
|
inputs['go-version'] = '1.13.0';
|
||||||
const toolPath = path.normalize('/cache/go/1.13.0/x64');
|
let toolPath = path.normalize('/cache/go/1.13.0/x64');
|
||||||
findSpy.mockImplementation(() => toolPath);
|
findSpy.mockImplementation(() => toolPath);
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
let expPath = path.join(toolPath, 'bin');
|
||||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles unhandled error and reports error', async () => {
|
it('handles unhandled error and reports error', async () => {
|
||||||
const errMsg = 'unhandled error message';
|
let errMsg = 'unhandled error message';
|
||||||
inputs['go-version'] = '1.13.0';
|
inputs['go-version'] = '1.13.0';
|
||||||
|
|
||||||
findSpy.mockImplementation(() => {
|
findSpy.mockImplementation(() => {
|
||||||
@ -359,12 +329,12 @@ describe('setup-go', () => {
|
|||||||
|
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
dlSpy.mockImplementation(() => '/some/temp/path');
|
dlSpy.mockImplementation(() => '/some/temp/path');
|
||||||
const toolPath = path.normalize('/cache/go/1.13.0/x64');
|
let toolPath = path.normalize('/cache/go/1.13.0/x64');
|
||||||
extractTarSpy.mockImplementation(() => '/some/other/temp/path');
|
extractTarSpy.mockImplementation(() => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(() => toolPath);
|
cacheSpy.mockImplementation(() => toolPath);
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
let expPath = path.join(toolPath, 'bin');
|
||||||
|
|
||||||
expect(dlSpy).toHaveBeenCalled();
|
expect(dlSpy).toHaveBeenCalled();
|
||||||
expect(extractTarSpy).toHaveBeenCalled();
|
expect(extractTarSpy).toHaveBeenCalled();
|
||||||
@ -382,14 +352,14 @@ describe('setup-go', () => {
|
|||||||
dlSpy.mockImplementation(() => 'C:\\temp\\some\\path');
|
dlSpy.mockImplementation(() => 'C:\\temp\\some\\path');
|
||||||
extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path');
|
extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path');
|
||||||
|
|
||||||
const toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64');
|
let toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64');
|
||||||
cacheSpy.mockImplementation(() => toolPath);
|
cacheSpy.mockImplementation(() => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
const expPath = path.win32.join(toolPath, 'bin');
|
let expPath = path.win32.join(toolPath, 'bin');
|
||||||
expect(dlSpy).toHaveBeenCalledWith(
|
expect(dlSpy).toHaveBeenCalledWith(
|
||||||
'https://go.dev/dl/go1.13.1.windows-amd64.zip',
|
'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip',
|
||||||
'C:\\temp\\go1.13.1.windows-amd64.zip',
|
'C:\\temp\\go1.13.1.windows-amd64.zip',
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
@ -414,25 +384,25 @@ describe('setup-go', () => {
|
|||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const versionSpec = '1.12.16';
|
let versionSpec = '1.12.16';
|
||||||
|
|
||||||
inputs['go-version'] = versionSpec;
|
inputs['go-version'] = versionSpec;
|
||||||
inputs['token'] = 'faketoken';
|
inputs['token'] = 'faketoken';
|
||||||
|
|
||||||
const expectedUrl =
|
let expectedUrl =
|
||||||
'https://github.com/actions/go-versions/releases/download/1.12.16-20200616.20/go-1.12.16-linux-x64.tar.gz';
|
'https://github.com/actions/go-versions/releases/download/1.12.16-20200616.20/go-1.12.16-linux-x64.tar.gz';
|
||||||
|
|
||||||
// ... but not in the local cache
|
// ... but not in the local cache
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
const toolPath = path.normalize('/cache/go/1.12.16/x64');
|
let toolPath = path.normalize('/cache/go/1.12.16/x64');
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
let expPath = path.join(toolPath, 'bin');
|
||||||
|
|
||||||
expect(dlSpy).toHaveBeenCalled();
|
expect(dlSpy).toHaveBeenCalled();
|
||||||
expect(extractTarSpy).toHaveBeenCalled();
|
expect(extractTarSpy).toHaveBeenCalled();
|
||||||
@ -451,25 +421,25 @@ describe('setup-go', () => {
|
|||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const versionSpec = '1.12';
|
let versionSpec = '1.12';
|
||||||
|
|
||||||
inputs['go-version'] = versionSpec;
|
inputs['go-version'] = versionSpec;
|
||||||
inputs['token'] = 'faketoken';
|
inputs['token'] = 'faketoken';
|
||||||
|
|
||||||
const expectedUrl =
|
let expectedUrl =
|
||||||
'https://github.com/actions/go-versions/releases/download/1.12.17-20200616.21/go-1.12.17-linux-x64.tar.gz';
|
'https://github.com/actions/go-versions/releases/download/1.12.17-20200616.21/go-1.12.17-linux-x64.tar.gz';
|
||||||
|
|
||||||
// ... but not in the local cache
|
// ... but not in the local cache
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
const toolPath = path.normalize('/cache/go/1.12.17/x64');
|
let toolPath = path.normalize('/cache/go/1.12.17/x64');
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
let expPath = path.join(toolPath, 'bin');
|
||||||
|
|
||||||
expect(dlSpy).toHaveBeenCalled();
|
expect(dlSpy).toHaveBeenCalled();
|
||||||
expect(extractTarSpy).toHaveBeenCalled();
|
expect(extractTarSpy).toHaveBeenCalled();
|
||||||
@ -488,7 +458,7 @@ describe('setup-go', () => {
|
|||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const versionSpec = '1.12.14';
|
let versionSpec = '1.12.14';
|
||||||
|
|
||||||
inputs['go-version'] = versionSpec;
|
inputs['go-version'] = versionSpec;
|
||||||
inputs['token'] = 'faketoken';
|
inputs['token'] = 'faketoken';
|
||||||
@ -497,13 +467,13 @@ describe('setup-go', () => {
|
|||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
const toolPath = path.normalize('/cache/go/1.12.14/x64');
|
let toolPath = path.normalize('/cache/go/1.12.14/x64');
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
let expPath = path.join(toolPath, 'bin');
|
||||||
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.12.14');
|
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.12.14');
|
||||||
expect(findSpy).toHaveBeenCalled();
|
expect(findSpy).toHaveBeenCalled();
|
||||||
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...');
|
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.12.14...');
|
||||||
@ -519,7 +489,7 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('reports a failed download', async () => {
|
it('reports a failed download', async () => {
|
||||||
const errMsg = 'unhandled download message';
|
let errMsg = 'unhandled download message';
|
||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
@ -540,7 +510,7 @@ describe('setup-go', () => {
|
|||||||
whichSpy.mockImplementation(async () => {
|
whichSpy.mockImplementation(async () => {
|
||||||
return '';
|
return '';
|
||||||
});
|
});
|
||||||
const added = await main.addBinToPath();
|
let added = await main.addBinToPath();
|
||||||
expect(added).toBeFalsy();
|
expect(added).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -558,8 +528,8 @@ describe('setup-go', () => {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
const added = await main.addBinToPath();
|
let added = await main.addBinToPath();
|
||||||
expect(added).toBeTruthy();
|
expect(added).toBeTruthy;
|
||||||
});
|
});
|
||||||
|
|
||||||
interface Annotation {
|
interface Annotation {
|
||||||
@ -573,9 +543,9 @@ describe('setup-go', () => {
|
|||||||
// problem matcher regex pattern tests
|
// problem matcher regex pattern tests
|
||||||
|
|
||||||
function testMatch(line: string): Annotation {
|
function testMatch(line: string): Annotation {
|
||||||
const annotation = <Annotation>{};
|
let annotation = <Annotation>{};
|
||||||
|
|
||||||
const match = matcherRegExp.exec(line);
|
let match = matcherRegExp.exec(line);
|
||||||
if (match) {
|
if (match) {
|
||||||
annotation.line = parseInt(match[matcherPattern.line], 10);
|
annotation.line = parseInt(match[matcherPattern.line], 10);
|
||||||
annotation.column = parseInt(match[matcherPattern.column], 10);
|
annotation.column = parseInt(match[matcherPattern.column], 10);
|
||||||
@ -587,8 +557,8 @@ describe('setup-go', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('matches on relative unix path', async () => {
|
it('matches on relative unix path', async () => {
|
||||||
const line = './main.go:13:2: undefined: fmt.Printl';
|
let line = './main.go:13:2: undefined: fmt.Printl';
|
||||||
const annotation = testMatch(line);
|
let annotation = testMatch(line);
|
||||||
expect(annotation).toBeDefined();
|
expect(annotation).toBeDefined();
|
||||||
expect(annotation.line).toBe(13);
|
expect(annotation.line).toBe(13);
|
||||||
expect(annotation.column).toBe(2);
|
expect(annotation.column).toBe(2);
|
||||||
@ -597,8 +567,8 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches on unix path up the tree', async () => {
|
it('matches on unix path up the tree', async () => {
|
||||||
const line = '../main.go:13:2: undefined: fmt.Printl';
|
let line = '../main.go:13:2: undefined: fmt.Printl';
|
||||||
const annotation = testMatch(line);
|
let annotation = testMatch(line);
|
||||||
expect(annotation).toBeDefined();
|
expect(annotation).toBeDefined();
|
||||||
expect(annotation.line).toBe(13);
|
expect(annotation.line).toBe(13);
|
||||||
expect(annotation.column).toBe(2);
|
expect(annotation.column).toBe(2);
|
||||||
@ -607,8 +577,8 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches on unix path down the tree', async () => {
|
it('matches on unix path down the tree', async () => {
|
||||||
const line = 'foo/main.go:13:2: undefined: fmt.Printl';
|
let line = 'foo/main.go:13:2: undefined: fmt.Printl';
|
||||||
const annotation = testMatch(line);
|
let annotation = testMatch(line);
|
||||||
expect(annotation).toBeDefined();
|
expect(annotation).toBeDefined();
|
||||||
expect(annotation.line).toBe(13);
|
expect(annotation.line).toBe(13);
|
||||||
expect(annotation.column).toBe(2);
|
expect(annotation.column).toBe(2);
|
||||||
@ -617,8 +587,8 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches on rooted unix path', async () => {
|
it('matches on rooted unix path', async () => {
|
||||||
const line = '/assert.go:4:1: missing return at end of function';
|
let line = '/assert.go:4:1: missing return at end of function';
|
||||||
const annotation = testMatch(line);
|
let annotation = testMatch(line);
|
||||||
expect(annotation).toBeDefined();
|
expect(annotation).toBeDefined();
|
||||||
expect(annotation.line).toBe(4);
|
expect(annotation.line).toBe(4);
|
||||||
expect(annotation.column).toBe(1);
|
expect(annotation.column).toBe(1);
|
||||||
@ -627,8 +597,8 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches on unix path with spaces', async () => {
|
it('matches on unix path with spaces', async () => {
|
||||||
const line = ' ./assert.go:5:2: missing return at end of function ';
|
let line = ' ./assert.go:5:2: missing return at end of function ';
|
||||||
const annotation = testMatch(line);
|
let annotation = testMatch(line);
|
||||||
expect(annotation).toBeDefined();
|
expect(annotation).toBeDefined();
|
||||||
expect(annotation.line).toBe(5);
|
expect(annotation.line).toBe(5);
|
||||||
expect(annotation.column).toBe(2);
|
expect(annotation.column).toBe(2);
|
||||||
@ -637,8 +607,8 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches on unix path with tabs', async () => {
|
it('matches on unix path with tabs', async () => {
|
||||||
const line = '\t./assert.go:5:2: missing return at end of function ';
|
let line = '\t./assert.go:5:2: missing return at end of function ';
|
||||||
const annotation = testMatch(line);
|
let annotation = testMatch(line);
|
||||||
expect(annotation).toBeDefined();
|
expect(annotation).toBeDefined();
|
||||||
expect(annotation.line).toBe(5);
|
expect(annotation.line).toBe(5);
|
||||||
expect(annotation.column).toBe(2);
|
expect(annotation.column).toBe(2);
|
||||||
@ -647,8 +617,8 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches on relative windows path', async () => {
|
it('matches on relative windows path', async () => {
|
||||||
const line = '.\\main.go:13:2: undefined: fmt.Printl';
|
let line = '.\\main.go:13:2: undefined: fmt.Printl';
|
||||||
const annotation = testMatch(line);
|
let annotation = testMatch(line);
|
||||||
expect(annotation).toBeDefined();
|
expect(annotation).toBeDefined();
|
||||||
expect(annotation.line).toBe(13);
|
expect(annotation.line).toBe(13);
|
||||||
expect(annotation.column).toBe(2);
|
expect(annotation.column).toBe(2);
|
||||||
@ -657,8 +627,8 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('matches on windows path up the tree', async () => {
|
it('matches on windows path up the tree', async () => {
|
||||||
const line = '..\\main.go:13:2: undefined: fmt.Printl';
|
let line = '..\\main.go:13:2: undefined: fmt.Printl';
|
||||||
const annotation = testMatch(line);
|
let annotation = testMatch(line);
|
||||||
expect(annotation).toBeDefined();
|
expect(annotation).toBeDefined();
|
||||||
expect(annotation.line).toBe(13);
|
expect(annotation.line).toBe(13);
|
||||||
expect(annotation.column).toBe(2);
|
expect(annotation.column).toBe(2);
|
||||||
@ -760,7 +730,7 @@ describe('setup-go', () => {
|
|||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const versionSpec = '1.13';
|
let versionSpec = '1.13';
|
||||||
|
|
||||||
inputs['go-version'] = versionSpec;
|
inputs['go-version'] = versionSpec;
|
||||||
inputs['check-latest'] = true;
|
inputs['check-latest'] = true;
|
||||||
@ -771,13 +741,13 @@ describe('setup-go', () => {
|
|||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
const toolPath = path.normalize('/cache/go/1.13.7/x64');
|
let toolPath = path.normalize('/cache/go/1.13.7/x64');
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
let expPath = path.join(toolPath, 'bin');
|
||||||
|
|
||||||
expect(dlSpy).toHaveBeenCalled();
|
expect(dlSpy).toHaveBeenCalled();
|
||||||
expect(extractTarSpy).toHaveBeenCalled();
|
expect(extractTarSpy).toHaveBeenCalled();
|
||||||
@ -797,7 +767,7 @@ describe('setup-go', () => {
|
|||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const versionSpec = '1.13';
|
let versionSpec = '1.13';
|
||||||
|
|
||||||
process.env['GITHUB_PATH'] = '';
|
process.env['GITHUB_PATH'] = '';
|
||||||
|
|
||||||
@ -811,19 +781,16 @@ describe('setup-go', () => {
|
|||||||
getManifestSpy.mockImplementation(() => {
|
getManifestSpy.mockImplementation(() => {
|
||||||
throw new Error('Unable to download manifest');
|
throw new Error('Unable to download manifest');
|
||||||
});
|
});
|
||||||
httpmGetJsonSpy.mockRejectedValue(
|
|
||||||
new Error('Unable to download manifest from raw URL')
|
|
||||||
);
|
|
||||||
getAllVersionsSpy.mockImplementationOnce(() => undefined);
|
getAllVersionsSpy.mockImplementationOnce(() => undefined);
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
const toolPath = path.normalize('/cache/go/1.13.7/x64');
|
let toolPath = path.normalize('/cache/go/1.13.7/x64');
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
let expPath = path.join(toolPath, 'bin');
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
`Failed to resolve version ${versionSpec} from manifest`
|
`Failed to resolve version ${versionSpec} from manifest`
|
||||||
@ -866,9 +833,6 @@ exclude example.com/thismodule v1.3.0
|
|||||||
|
|
||||||
use .
|
use .
|
||||||
|
|
||||||
`;
|
|
||||||
|
|
||||||
const toolVersionsContents = `golang 1.23
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
it('reads version from go.mod', async () => {
|
it('reads version from go.mod', async () => {
|
||||||
@ -895,18 +859,6 @@ use .
|
|||||||
expect(logSpy).toHaveBeenCalledWith('matching 1.19...');
|
expect(logSpy).toHaveBeenCalledWith('matching 1.19...');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('reads version from .tool-versions', async () => {
|
|
||||||
inputs['go-version-file'] = '.tool-versions';
|
|
||||||
existsSpy.mockImplementation(() => true);
|
|
||||||
readFileSpy.mockImplementation(() => Buffer.from(toolVersionsContents));
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.23');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.23...');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('matching 1.23...');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reads version from .go-version', async () => {
|
it('reads version from .go-version', async () => {
|
||||||
inputs['go-version-file'] = '.go-version';
|
inputs['go-version-file'] = '.go-version';
|
||||||
existsSpy.mockImplementation(() => true);
|
existsSpy.mockImplementation(() => true);
|
||||||
@ -958,16 +910,16 @@ use .
|
|||||||
inputs['go-version'] = version;
|
inputs['go-version'] = version;
|
||||||
inputs['architecture'] = arch;
|
inputs['architecture'] = arch;
|
||||||
|
|
||||||
const expectedUrl =
|
let expectedUrl =
|
||||||
platform === 'win32'
|
platform === 'win32'
|
||||||
? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}`
|
? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}`
|
||||||
: `https://go.dev/dl/go${version}.${osSpec}-${arch}.${fileExtension}`;
|
: `https://storage.googleapis.com/golang/go${version}.${osSpec}-${arch}.${fileExtension}`;
|
||||||
|
|
||||||
// ... but not in the local cache
|
// ... but not in the local cache
|
||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
const toolPath = path.normalize(`/cache/go/${version}/${arch}`);
|
let toolPath = path.normalize(`/cache/go/${version}/${arch}`);
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
@ -992,7 +944,7 @@ use .
|
|||||||
findSpy.mockImplementation(() => '');
|
findSpy.mockImplementation(() => '');
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
dlSpy.mockImplementation(async () => '/some/temp/path');
|
||||||
const toolPath = path.normalize(`/cache/go/${alias}/${arch}`);
|
let toolPath = path.normalize(`/cache/go/${alias}/${arch}`);
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
cacheSpy.mockImplementation(async () => toolPath);
|
||||||
|
|
||||||
await main.run();
|
await main.run();
|
||||||
@ -1005,104 +957,4 @@ use .
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('go-version-file-toolchain', () => {
|
|
||||||
const goVersions = ['1.22.0', '1.21rc2', '1.18'];
|
|
||||||
const placeholderVersion = '1.19';
|
|
||||||
const buildGoMod = (
|
|
||||||
goVersion: string,
|
|
||||||
toolchainVersion: string
|
|
||||||
) => `module example.com/mymodule
|
|
||||||
|
|
||||||
go ${goVersion}
|
|
||||||
|
|
||||||
toolchain go${toolchainVersion}
|
|
||||||
|
|
||||||
require (
|
|
||||||
example.com/othermodule v1.2.3
|
|
||||||
example.com/thismodule v1.2.3
|
|
||||||
example.com/thatmodule v1.2.3
|
|
||||||
)
|
|
||||||
|
|
||||||
replace example.com/thatmodule => ../thatmodule
|
|
||||||
exclude example.com/thismodule v1.3.0
|
|
||||||
`;
|
|
||||||
|
|
||||||
const buildGoWork = (
|
|
||||||
goVersion: string,
|
|
||||||
toolchainVersion: string
|
|
||||||
) => `go 1.19
|
|
||||||
|
|
||||||
toolchain go${toolchainVersion}
|
|
||||||
|
|
||||||
use .
|
|
||||||
|
|
||||||
`;
|
|
||||||
|
|
||||||
goVersions.forEach(version => {
|
|
||||||
[
|
|
||||||
{
|
|
||||||
goVersionfile: 'go.mod',
|
|
||||||
fileContents: Buffer.from(buildGoMod(placeholderVersion, version)),
|
|
||||||
expected_version: version,
|
|
||||||
desc: 'from toolchain directive'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
goVersionfile: 'go.work',
|
|
||||||
fileContents: Buffer.from(buildGoMod(placeholderVersion, version)),
|
|
||||||
expected_version: version,
|
|
||||||
desc: 'from toolchain directive'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
goVersionfile: 'go.mod',
|
|
||||||
fileContents: Buffer.from(buildGoMod(placeholderVersion, version)),
|
|
||||||
gotoolchain_env: 'local',
|
|
||||||
expected_version: placeholderVersion,
|
|
||||||
desc: 'from go directive when GOTOOLCHAIN is local'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
goVersionfile: 'go.work',
|
|
||||||
fileContents: Buffer.from(buildGoMod(placeholderVersion, version)),
|
|
||||||
gotoolchain_env: 'local',
|
|
||||||
expected_version: placeholderVersion,
|
|
||||||
desc: 'from go directive when GOTOOLCHAIN is local'
|
|
||||||
}
|
|
||||||
].forEach(test => {
|
|
||||||
it(`reads version (${version}) in ${test.goVersionfile} ${test.desc}`, async () => {
|
|
||||||
inputs['go-version-file'] = test.goVersionfile;
|
|
||||||
if (test.gotoolchain_env !== undefined) {
|
|
||||||
process.env[im.GOTOOLCHAIN_ENV_VAR] = test.gotoolchain_env;
|
|
||||||
}
|
|
||||||
existsSpy.mockImplementation(() => true);
|
|
||||||
readFileSpy.mockImplementation(() => Buffer.from(test.fileContents));
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Setup go version spec ${test.expected_version}`
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Attempting to download ${test.expected_version}...`
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`matching ${test.expected_version}...`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('exports GOTOOLCHAIN and sets it in current process env', async () => {
|
|
||||||
inputs['go-version'] = '1.21.0';
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
|
|
||||||
const vars: {[key: string]: string} = {};
|
|
||||||
exportVarSpy.mockImplementation((name: string, val: string) => {
|
|
||||||
vars[name] = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
expect(vars).toStrictEqual({GOTOOLCHAIN: 'local'});
|
|
||||||
expect(process.env).toHaveProperty('GOTOOLCHAIN', 'local');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,52 +0,0 @@
|
|||||||
import {isSelfHosted} from '../src/utils';
|
|
||||||
|
|
||||||
describe('utils', () => {
|
|
||||||
describe('isSelfHosted', () => {
|
|
||||||
let AGENT_ISSELFHOSTED: string | undefined;
|
|
||||||
let RUNNER_ENVIRONMENT: string | undefined;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
AGENT_ISSELFHOSTED = process.env['AGENT_ISSELFHOSTED'];
|
|
||||||
delete process.env['AGENT_ISSELFHOSTED'];
|
|
||||||
RUNNER_ENVIRONMENT = process.env['RUNNER_ENVIRONMENT'];
|
|
||||||
delete process.env['RUNNER_ENVIRONMENT'];
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
if (AGENT_ISSELFHOSTED === undefined) {
|
|
||||||
delete process.env['AGENT_ISSELFHOSTED'];
|
|
||||||
} else {
|
|
||||||
process.env['AGENT_ISSELFHOSTED'] = AGENT_ISSELFHOSTED;
|
|
||||||
}
|
|
||||||
if (RUNNER_ENVIRONMENT === undefined) {
|
|
||||||
delete process.env['RUNNER_ENVIRONMENT'];
|
|
||||||
} else {
|
|
||||||
process.env['RUNNER_ENVIRONMENT'] = RUNNER_ENVIRONMENT;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('isSelfHosted should be true if no environment variables set', () => {
|
|
||||||
expect(isSelfHosted()).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('isSelfHosted should be true if environment variable is not set to denote GitHub hosted', () => {
|
|
||||||
process.env['RUNNER_ENVIRONMENT'] = 'some';
|
|
||||||
expect(isSelfHosted()).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('isSelfHosted should be true if environment variable set to denote Azure Pipelines self hosted', () => {
|
|
||||||
process.env['AGENT_ISSELFHOSTED'] = '1';
|
|
||||||
expect(isSelfHosted()).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('isSelfHosted should be false if environment variable set to denote GitHub hosted', () => {
|
|
||||||
process.env['RUNNER_ENVIRONMENT'] = 'github-hosted';
|
|
||||||
expect(isSelfHosted()).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('isSelfHosted should be false if environment variable is not set to denote Azure Pipelines self hosted', () => {
|
|
||||||
process.env['AGENT_ISSELFHOSTED'] = 'some';
|
|
||||||
expect(isSelfHosted()).toBeFalsy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,62 +0,0 @@
|
|||||||
import fs from 'fs';
|
|
||||||
import * as io from '@actions/io';
|
|
||||||
import * as tc from '@actions/tool-cache';
|
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
describe('Windows performance workaround', () => {
|
|
||||||
let mkdirSpy: jest.SpyInstance;
|
|
||||||
let symlinkSpy: jest.SpyInstance;
|
|
||||||
let statSpy: jest.SpyInstance;
|
|
||||||
let readdirSpy: jest.SpyInstance;
|
|
||||||
let writeFileSpy: jest.SpyInstance;
|
|
||||||
let rmRFSpy: jest.SpyInstance;
|
|
||||||
let mkdirPSpy: jest.SpyInstance;
|
|
||||||
let cpSpy: jest.SpyInstance;
|
|
||||||
|
|
||||||
let runnerToolCache: string | undefined;
|
|
||||||
beforeEach(() => {
|
|
||||||
mkdirSpy = jest.spyOn(fs, 'mkdir');
|
|
||||||
symlinkSpy = jest.spyOn(fs, 'symlinkSync');
|
|
||||||
statSpy = jest.spyOn(fs, 'statSync');
|
|
||||||
readdirSpy = jest.spyOn(fs, 'readdirSync');
|
|
||||||
writeFileSpy = jest.spyOn(fs, 'writeFileSync');
|
|
||||||
rmRFSpy = jest.spyOn(io, 'rmRF');
|
|
||||||
mkdirPSpy = jest.spyOn(io, 'mkdirP');
|
|
||||||
cpSpy = jest.spyOn(io, 'cp');
|
|
||||||
|
|
||||||
// default implementations
|
|
||||||
// @ts-ignore - not implement unused methods
|
|
||||||
statSpy.mockImplementation(() => ({
|
|
||||||
isDirectory: () => true
|
|
||||||
}));
|
|
||||||
readdirSpy.mockImplementation(() => []);
|
|
||||||
writeFileSpy.mockImplementation(() => {});
|
|
||||||
mkdirSpy.mockImplementation(() => {});
|
|
||||||
symlinkSpy.mockImplementation(() => {});
|
|
||||||
rmRFSpy.mockImplementation(() => Promise.resolve());
|
|
||||||
mkdirPSpy.mockImplementation(() => Promise.resolve());
|
|
||||||
cpSpy.mockImplementation(() => Promise.resolve());
|
|
||||||
|
|
||||||
runnerToolCache = process.env['RUNNER_TOOL_CACHE'];
|
|
||||||
});
|
|
||||||
afterEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
process.env['RUNNER_TOOL_CACHE'] = runnerToolCache;
|
|
||||||
});
|
|
||||||
// cacheWindowsToolkitDir depends on implementation of tc.cacheDir
|
|
||||||
// with the assumption that target dir is passed by RUNNER_TOOL_CACHE environment variable
|
|
||||||
// Make sure the implementation has not been changed
|
|
||||||
it('addExecutablesToCache should depend on env[RUNNER_TOOL_CACHE]', async () => {
|
|
||||||
process.env['RUNNER_TOOL_CACHE'] = '/faked-hostedtoolcache1';
|
|
||||||
const cacheDir1 = await tc.cacheDir('/qzx', 'go', '1.2.3', 'arch');
|
|
||||||
expect(cacheDir1).toBe(
|
|
||||||
path.join('/', 'faked-hostedtoolcache1', 'go', '1.2.3', 'arch')
|
|
||||||
);
|
|
||||||
|
|
||||||
process.env['RUNNER_TOOL_CACHE'] = '/faked-hostedtoolcache2';
|
|
||||||
const cacheDir2 = await tc.cacheDir('/qzx', 'go', '1.2.3', 'arch');
|
|
||||||
expect(cacheDir2).toBe(
|
|
||||||
path.join('/', 'faked-hostedtoolcache2', 'go', '1.2.3', 'arch')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
12
action.yml
12
action.yml
@ -3,20 +3,20 @@ description: 'Setup a Go environment and add it to the PATH'
|
|||||||
author: 'GitHub'
|
author: 'GitHub'
|
||||||
inputs:
|
inputs:
|
||||||
go-version:
|
go-version:
|
||||||
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges. Be sure to enclose this option in single quotation marks.'
|
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges.'
|
||||||
go-version-file:
|
go-version-file:
|
||||||
description: 'Path to the go.mod, go.work, .go-version, or .tool-versions file.'
|
description: 'Path to the go.mod or go.work file.'
|
||||||
check-latest:
|
check-latest:
|
||||||
description: 'Set this option to true if you want the action to always check for the latest available version that satisfies the version spec'
|
description: 'Set this option to true if you want the action to always check for the latest available version that satisfies the version spec'
|
||||||
default: false
|
default: false
|
||||||
token:
|
token:
|
||||||
description: Used to pull Go distributions from go-versions. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
|
description: Used to pull node distributions from go-versions. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
|
||||||
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
||||||
cache:
|
cache:
|
||||||
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
|
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
|
||||||
default: true
|
default: false
|
||||||
cache-dependency-path:
|
cache-dependency-path:
|
||||||
description: 'Used to specify the path to a dependency file (e.g., go.mod, go.sum)'
|
description: 'Used to specify the path to a dependency file - go.sum'
|
||||||
architecture:
|
architecture:
|
||||||
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
|
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
|
||||||
outputs:
|
outputs:
|
||||||
@ -25,7 +25,7 @@ outputs:
|
|||||||
cache-hit:
|
cache-hit:
|
||||||
description: 'A boolean value to indicate if a cache was hit'
|
description: 'A boolean value to indicate if a cache was hit'
|
||||||
runs:
|
runs:
|
||||||
using: 'node24'
|
using: 'node16'
|
||||||
main: 'dist/setup/index.js'
|
main: 'dist/setup/index.js'
|
||||||
post: 'dist/cache-save/index.js'
|
post: 'dist/cache-save/index.js'
|
||||||
post-if: success()
|
post-if: success()
|
||||||
|
|||||||
162924
dist/cache-save/index.js
vendored
162924
dist/cache-save/index.js
vendored
File diff suppressed because one or more lines are too long
167400
dist/setup/index.js
vendored
167400
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
@ -32,7 +32,7 @@ We don't pursue the goal to provide wide customization of caching in scope of `a
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '18'
|
go-version: '18'
|
||||||
@ -43,7 +43,7 @@ steps:
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '18'
|
go-version: '18'
|
||||||
@ -53,7 +53,7 @@ steps:
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: '18'
|
go-version: '18'
|
||||||
|
|||||||
@ -1,444 +0,0 @@
|
|||||||
# Advanced Usage
|
|
||||||
- [Using the go-version input](advanced-usage.md#using-the-go-version-input)
|
|
||||||
- [Specifying a go version](advanced-usage.md#specifying-a-go-version)
|
|
||||||
- [Matrix testing](advanced-usage.md#matrix-testing)
|
|
||||||
- [Using the go-version-file input](advanced-usage.md#using-the-go-version-file-input)
|
|
||||||
- [Check latest version](advanced-usage.md#check-latest-version)
|
|
||||||
- [Caching](advanced-usage.md#caching)
|
|
||||||
- [Caching in monorepos](advanced-usage.md#caching-in-monorepos)
|
|
||||||
- [Caching in multi-module repositories](advanced-usage.md#caching-in-multi-module-repositories)
|
|
||||||
- [Multi-target builds](advanced-usage.md#multi-target-builds)
|
|
||||||
- [Cache invalidation on source changes](advanced-usage.md#cache-invalidation-on-source-changes)
|
|
||||||
- [Restore-only caches](advanced-usage.md#restore-only-caches)
|
|
||||||
- [Parallel builds](advanced-usage.md#parallel-builds)
|
|
||||||
- [Outputs](advanced-usage.md#outputs)
|
|
||||||
- [Using `setup-go` on GHES](advanced-usage.md#using-setup-go-on-ghes)
|
|
||||||
|
|
||||||
## Using the `go-version` input
|
|
||||||
|
|
||||||
### Specifying a Go version
|
|
||||||
|
|
||||||
For repeatable builds, specify the **exact major, minor, and patch version** (such as `1.25.5`):
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.25.5'
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
- The only downside is that setup may take a little longer. If the exact version is not already installed on the runner due to more recent versions, the exact version will have to be downloaded.
|
|
||||||
|
|
||||||
You can specify **only a major and minor version** if you are okay with the most recent patch version being used:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.25'
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
- There will be a single patch version already installed on each runner for every minor version of Go that is supported.
|
|
||||||
- The preinstalled patch version is generally the latest available. When a new patch is released, it replaces the previously preinstalled version on the runner.
|
|
||||||
- Using the most recent patch version speeds up setup because the required Go version is already installed on the runner and no download is needed.
|
|
||||||
|
|
||||||
To try a **pre-release**:
|
|
||||||
Download and use beta or RC Go versions as needed.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
# RC version
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.25.0-rc.2'
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
# Beta version
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.19.0-beta.1'
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
Using **stable/oldstable aliases**:
|
|
||||||
|
|
||||||
If `stable` is provided, the action will get the latest stable version from the [`go-versions`](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository manifest.
|
|
||||||
|
|
||||||
If `oldstable` is provided, the action resolves it to the latest patch release of the previous stable Go minor version (for example, if the latest stable is `1.25.x`, `oldstable` resolves to `1.24.x`, where `x` is the latest patch release).
|
|
||||||
|
|
||||||
**Note:** Using these aliases will result in the same version as when using the corresponding minor release with the `check-latest` input set to `true`.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: 'stable'
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: 'oldstable'
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use **SemVer's version range syntax**, for instance:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '^1.25.1'
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '>=1.24.0-rc.1'
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
### Matrix testing
|
|
||||||
|
|
||||||
Using `setup-go` it's possible to use the [matrix syntax](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) to install several versions of Go:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
go: [ '1.24', '1.25' ]
|
|
||||||
name: Go ${{ matrix.go }} sample
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- name: Setup go
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go }}
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
Exclude a specific Go version:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
||||||
go: [ '1.22', '1.24', '1.25']
|
|
||||||
exclude:
|
|
||||||
- os: macos-latest
|
|
||||||
go: '1.22'
|
|
||||||
- os: windows-latest
|
|
||||||
go: '1.25'
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- name: Setup go
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go }}
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
## Using the `go-version-file` input
|
|
||||||
|
|
||||||
`setup-go` action can read the Go version from a version file. `go-version-file` input is used for specifying the path to the version file. If the file supplied to the `go-version-file` input doesn't exist, the action will fail with an error. This input supports go.mod, go.work, .go-version, and .tool-versions files.
|
|
||||||
|
|
||||||
If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used. The `.tool-versions` file supports version specifications in accordance with asdf standards, adhering to Semantic Versioning ([semver](https://semver.org)).
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version-file: 'path/to/go.mod' # Read Go version from go.mod
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
- Uses the `toolchain` directive if present, otherwise the action falls back to the `go` directive.
|
|
||||||
|
|
||||||
- The `go` directive in `go.mod` can specify a patch version or omit it altogether (e.g., `go 1.25.0` or `go 1.25`). If a patch version is specified, that specific patch version will be used. If no patch version is specified, it will search for the latest available patch version in the cache,
|
|
||||||
[versions-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json), and the
|
|
||||||
[official Go language website](https://go.dev/dl/?mode=json&include=all), in that order.
|
|
||||||
|
|
||||||
> The action will search for the `go.mod` file relative to the repository root.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version-file: '.go-version' # Read Go version from .go-version
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version-file: '.tool-versions' # Read Go version from .tool-versions
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version-file: 'go.work' # Read Go version from go.work
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
## Check latest version
|
|
||||||
|
|
||||||
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability
|
|
||||||
and if you want to ensure a specific Go version is always used.
|
|
||||||
|
|
||||||
If `check-latest` is set to `true`, the action first checks if the cached version is the latest one. If the locally
|
|
||||||
cached version is not the most up-to-date, a Go version will then be downloaded. Set `check-latest` to `true` if you
|
|
||||||
want the most up-to-date Go version to always be used. It supports major (e.g., "1") and major.minor (e.g., "1.25") version selectors, always resolving to the latest matching patch release.
|
|
||||||
|
|
||||||
> Setting `check-latest` to `true` has performance implications as downloading Go versions is slower than using cached
|
|
||||||
> versions.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.25'
|
|
||||||
check-latest: true
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
## Caching
|
|
||||||
|
|
||||||
### Caching in monorepos
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.25'
|
|
||||||
cache-dependency-path: subdir/go.sum
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
### Caching in multi-module repositories
|
|
||||||
|
|
||||||
`cache-dependency-path` input accepts glob patterns and multi-line values:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.25'
|
|
||||||
cache-dependency-path: '**/go.sum'
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.25'
|
|
||||||
cache-dependency-path: |
|
|
||||||
subdir/go.sum
|
|
||||||
tools/go.sum
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
### Multi-target builds
|
|
||||||
|
|
||||||
`cache-dependency-path` isn’t limited to dependency files (like `go.sum`). It can also include files that capture build settings (for example, `GOOS`/`GOARCH`). This allows separate caches per target platform (OS/architecture) and helps avoid reusing caches across incompatible builds.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
env:
|
|
||||||
GOOS: ...
|
|
||||||
GOARCH: ...
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- run: echo "$GOOS $GOARCH" > env.txt
|
|
||||||
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.25'
|
|
||||||
cache-dependency-path: |
|
|
||||||
go.sum
|
|
||||||
env.txt
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
### Cache invalidation on source changes
|
|
||||||
|
|
||||||
Besides dependencies, the action can also cache build outputs (the [`GOCACHE`](https://pkg.go.dev/cmd/go#hdr-Build_and_test_caching) directory). By default, this cache is not updated based on source changes to help avoid unpredictable and frequent cache invalidation. To invalidate the cache when source files change, include source files in the `cache-dependency-path` input.
|
|
||||||
|
|
||||||
> **Note:** Including patterns like `**/*.go` can create new caches on many commits, increasing cache storage and potentially slowing workflows due to more frequent uploads/downloads.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
go-version: '1.25'
|
|
||||||
cache-dependency-path: |
|
|
||||||
go.sum
|
|
||||||
**/*.go
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
### Restore-only caches
|
|
||||||
|
|
||||||
Restore caches without saving new entries. This can help reduce cache writes and storage usage in workflows that only need to read from the cache:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
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.25.5'
|
|
||||||
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.mod') }}
|
|
||||||
- name: Download modules
|
|
||||||
run: go mod download
|
|
||||||
- name: Build
|
|
||||||
run: go build ./...
|
|
||||||
```
|
|
||||||
|
|
||||||
> If there are several builds on the same repo, it may make sense to create a cache in one build and use it in others. The action [actions/cache/restore](https://github.com/actions/cache/tree/main/restore#only-restore-cache)
|
|
||||||
should be used in this case.
|
|
||||||
|
|
||||||
### Parallel builds
|
|
||||||
|
|
||||||
To avoid race conditions during parallel builds, either use distinct cache keys with [actions/cache](https://github.com/actions/cache/blob/main/examples.md#go---modules), or create the cache in only one build and [restore](#restore-only-caches) it in the other builds.
|
|
||||||
|
|
||||||
## Outputs
|
|
||||||
|
|
||||||
### `go-version`
|
|
||||||
|
|
||||||
Using **go-version** output, it's possible to get the precise Go version installed by the action. This output is useful when the input `go-version` is given as a range, but down the line you need to operate (such as in an `if:` statement) with the exact installed version (e.g. 1.24.11).
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
id: go124
|
|
||||||
with:
|
|
||||||
go-version: '^1.24'
|
|
||||||
- run: echo "Installed Go version: ${{ steps.go124.outputs.go-version }}"
|
|
||||||
```
|
|
||||||
|
|
||||||
### `cache-hit`
|
|
||||||
|
|
||||||
**cache-hit** output is available with a boolean value that indicates whether a cache hit occurred on the primary key:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v6
|
|
||||||
- uses: actions/setup-go@v6
|
|
||||||
id: go124
|
|
||||||
with:
|
|
||||||
go-version: '1.24'
|
|
||||||
cache: true
|
|
||||||
- run: echo "Was the Go cache restored? ${{ steps.go124.outputs.cache-hit }}" # true if cache-hit occurred
|
|
||||||
```
|
|
||||||
|
|
||||||
## Using `setup-go` on GHES
|
|
||||||
|
|
||||||
### Avoiding rate limit issues
|
|
||||||
|
|
||||||
`setup-go` comes pre-installed on the appliance with GHES if Actions is enabled.
|
|
||||||
When dynamically downloading Go distributions, `setup-go` downloads distributions from [`actions/go-versions`](https://github.com/actions/go-versions) on github.com (outside of the appliance).
|
|
||||||
|
|
||||||
These calls to `actions/go-versions` are made via unauthenticated requests, which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting).
|
|
||||||
If more requests are made within the time frame, then the action leverages the `raw API` to retrieve the version-manifest. This approach does not impose a rate limit and hence facilitates unrestricted consumption. This is particularly beneficial for GHES runners, which often share the same IP, to avoid the quick exhaustion of the unauthenticated rate limit.
|
|
||||||
If that fails as well the action will try to download versions directly from [go.dev](https://go.dev/dl).
|
|
||||||
|
|
||||||
If that fails as well you can get a higher rate limit with [generating a personal access token on github.com](https://github.com/settings/tokens/new) and passing it as the `token` input to the action:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
uses: actions/setup-go@v6
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
|
||||||
go-version: '1.25'
|
|
||||||
```
|
|
||||||
|
|
||||||
### No access to github.com
|
|
||||||
|
|
||||||
If the runner is not able to access github.com, any Go versions requested during a workflow run must come from the runner's tool cache.
|
|
||||||
See "[Setting up the tool cache on self-hosted runners without internet access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)"
|
|
||||||
for more information.
|
|
||||||
@ -52,7 +52,7 @@ Pull requests are the easiest way to contribute changes to git repos at GitHub.
|
|||||||
|
|
||||||
- Please check that no one else has already created a pull request with these changes
|
- Please check that no one else has already created a pull request with these changes
|
||||||
- Use a "feature branch" for your changes. That separates the changes in the pull request from your other changes and makes it easy to edit/amend commits in the pull request
|
- Use a "feature branch" for your changes. That separates the changes in the pull request from your other changes and makes it easy to edit/amend commits in the pull request
|
||||||
- **Run `pre-checkin` script to format, lint, build and test changes**
|
- **Run `pre-checkin` script to format, build and test changes**
|
||||||
- Make sure your changes are well formatted and that all tests are passing
|
- Make sure your changes are well formatted and that all tests are passing
|
||||||
- If your pull request is connected to an open issue, please, leave a link to this issue in the `Related issue:` section
|
- If your pull request is connected to an open issue, please, leave a link to this issue in the `Related issue:` section
|
||||||
- If you later need to add new commits to the pull request, you can simply commit the changes to the local branch and then push them. The pull request gets automatically updated
|
- If you later need to add new commits to the pull request, you can simply commit the changes to the local branch and then push them. The pull request gets automatically updated
|
||||||
@ -61,7 +61,6 @@ Pull requests are the easiest way to contribute changes to git repos at GitHub.
|
|||||||
|
|
||||||
- To implement new features or fix bugs, you need to make changes to the `.ts` files, which are located in the `src` folder
|
- To implement new features or fix bugs, you need to make changes to the `.ts` files, which are located in the `src` folder
|
||||||
- To comply with the code style, **you need to run the `format` script**
|
- To comply with the code style, **you need to run the `format` script**
|
||||||
- To lint the code, **you need to run the `lint:fix` script**
|
|
||||||
- To transpile source code to `javascript` we use [NCC](https://github.com/vercel/ncc). **It is very important to run the `build` script after making changes**, otherwise your changes will not get into the final `javascript` build
|
- To transpile source code to `javascript` we use [NCC](https://github.com/vercel/ncc). **It is very important to run the `build` script after making changes**, otherwise your changes will not get into the final `javascript` build
|
||||||
- You can also start formatting, building code, and testing with a single `pre-checkin` command
|
- You can also start formatting, building code, and testing with a single `pre-checkin` command
|
||||||
|
|
||||||
|
|||||||
9743
package-lock.json
generated
9743
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user