Compare commits
2 Commits
main
...
thboop/nod
Author | SHA1 | Date | |
---|---|---|---|
|
4314d44d94 | ||
|
28c3d5cef9 |
@ -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
|
|
||||||
}
|
|
||||||
};
|
|
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1,2 +1 @@
|
|||||||
* text=auto eol=lf
|
|
||||||
.licenses/** -diff linguist-generated=true
|
.licenses/** -diff linguist-generated=true
|
2
.github/ISSUE_TEMPLATE/config.yml
vendored
2
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1 +1 @@
|
|||||||
blank_issues_enabled: false
|
blank_issues_enabled: false
|
18
.github/workflows/basic-validation.yml
vendored
18
.github/workflows/basic-validation.yml
vendored
@ -1,18 +0,0 @@
|
|||||||
name: Basic validation
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
pull_request:
|
|
||||||
paths-ignore:
|
|
||||||
- '**.md'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
call-basic-validation:
|
|
||||||
name: Basic validation
|
|
||||||
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
|
|
||||||
with:
|
|
||||||
node-version: '20'
|
|
42
.github/workflows/check-dist.yml
vendored
42
.github/workflows/check-dist.yml
vendored
@ -1,3 +1,8 @@
|
|||||||
|
# `dist/index.js` is a special file in Actions.
|
||||||
|
# When you reference an action with `uses:` in a workflow,
|
||||||
|
# `index.js` is the code that will run.
|
||||||
|
# For our project, we generate this file through a build process from other source files.
|
||||||
|
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
|
||||||
name: Check dist/
|
name: Check dist/
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@ -12,8 +17,35 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
call-check-dist:
|
check-dist:
|
||||||
name: Check dist/
|
runs-on: ubuntu-latest
|
||||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
|
||||||
with:
|
steps:
|
||||||
node-version: '20'
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Set Node.js 16.x
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 16.x
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Rebuild the dist/ directory
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Compare the expected and actual dist/ directories
|
||||||
|
run: |
|
||||||
|
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
|
||||||
|
echo "Detected uncommitted changes after build. See status below:"
|
||||||
|
git diff
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
id: diff
|
||||||
|
|
||||||
|
# If index.js was different than expected, upload the expected version as an artifact
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
path: dist/
|
||||||
|
14
.github/workflows/codeql-analysis.yml
vendored
14
.github/workflows/codeql-analysis.yml
vendored
@ -1,14 +0,0 @@
|
|||||||
name: CodeQL analysis
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
pull_request:
|
|
||||||
branches: [main]
|
|
||||||
schedule:
|
|
||||||
- cron: '0 3 * * 0'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
call-codeQL-analysis:
|
|
||||||
name: CodeQL analysis
|
|
||||||
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main
|
|
16
.github/workflows/licensed.yml
vendored
16
.github/workflows/licensed.yml
vendored
@ -9,6 +9,16 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
call-licensed:
|
test:
|
||||||
name: Licensed
|
runs-on: ubuntu-latest
|
||||||
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main
|
name: Check licenses
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- run: npm ci
|
||||||
|
- name: Install licensed
|
||||||
|
run: |
|
||||||
|
cd $RUNNER_TEMP
|
||||||
|
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz
|
||||||
|
sudo tar -xzf licensed.tar.gz
|
||||||
|
sudo mv licensed /usr/local/bin/licensed
|
||||||
|
- run: licensed status
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
name: Release new action version
|
name: Release new action version
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [released]
|
types: [released]
|
||||||
@ -22,7 +21,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.2.2
|
uses: actions/publish-action@v0.1.0
|
||||||
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
|
|
134
.github/workflows/versions.yml
vendored
134
.github/workflows/versions.yml
vendored
@ -1,5 +1,4 @@
|
|||||||
name: Validate 'setup-go'
|
name: Validate 'setup-go'
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
@ -13,57 +12,6 @@ on:
|
|||||||
- cron: 0 0 * * *
|
- cron: 0 0 * * *
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stable:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup Go Stable
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: stable
|
|
||||||
- name: Verify Go
|
|
||||||
run: go version
|
|
||||||
|
|
||||||
oldstable:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup Go oldStable
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: oldstable
|
|
||||||
- name: Verify Go
|
|
||||||
run: go version
|
|
||||||
|
|
||||||
aliases-arch:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
version: [stable, oldstable]
|
|
||||||
architecture: [x64, x32]
|
|
||||||
exclude:
|
|
||||||
- os: macos-latest
|
|
||||||
architecture: x32
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }}
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.version }}
|
|
||||||
architecture: ${{ matrix.architecture }}
|
|
||||||
- name: Verify Go
|
|
||||||
run: go version
|
|
||||||
|
|
||||||
local-cache:
|
local-cache:
|
||||||
name: Setup local-cache version
|
name: Setup local-cache version
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@ -71,10 +19,10 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
go: [1.20.14, 1.21.10, 1.22.3]
|
go: [1.12, 1.13, 1.14]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: setup-go ${{ matrix.go }}
|
- name: setup-go ${{ matrix.go }}
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -85,55 +33,6 @@ jobs:
|
|||||||
run: __tests__/verify-go.sh ${{ matrix.go }}
|
run: __tests__/verify-go.sh ${{ matrix.go }}
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
check-latest:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
go-version: [1.20.14, 1.21]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup Go and check latest
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go-version }}
|
|
||||||
check-latest: true
|
|
||||||
- name: Verify Go
|
|
||||||
run: go version
|
|
||||||
|
|
||||||
go-version-file:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup Go and check latest
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version-file: __tests__/data/go.mod
|
|
||||||
- name: verify go
|
|
||||||
run: __tests__/verify-go.sh 1.20.14
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
go-version-file-with-gowork:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup Go and check latest
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version-file: __tests__/data/go.work
|
|
||||||
- name: verify go
|
|
||||||
run: __tests__/verify-go.sh 1.21
|
|
||||||
shell: bash
|
|
||||||
|
|
||||||
setup-versions-from-manifest:
|
setup-versions-from-manifest:
|
||||||
name: Setup ${{ matrix.go }} ${{ matrix.os }}
|
name: Setup ${{ matrix.go }} ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
@ -141,16 +40,16 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
go: [1.20.14, 1.21.10, 1.22.3]
|
go: [1.12.16, 1.13.11, 1.14.3]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: setup-go ${{ matrix.go }}
|
- name: setup-go ${{ matrix.go }}
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
- name: verify go
|
- name: verify go
|
||||||
run: __tests__/verify-go.sh ${{ matrix.go }}
|
run: __tests__/verify-go.sh ${{ matrix.go }}
|
||||||
shell: bash
|
shell: bash
|
||||||
@ -162,10 +61,10 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
go: [1.20.14, 1.21]
|
go: [1.7, 1.8.6]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: setup-go ${{ matrix.go }}
|
- name: setup-go ${{ matrix.go }}
|
||||||
uses: ./
|
uses: ./
|
||||||
@ -175,20 +74,3 @@ jobs:
|
|||||||
- name: verify go
|
- name: verify go
|
||||||
run: __tests__/verify-go.sh ${{ matrix.go }}
|
run: __tests__/verify-go.sh ${{ matrix.go }}
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
architecture:
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
|
||||||
go-version: [1.20.14, 1.21]
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Setup Go and check latest
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go-version }}
|
|
||||||
architecture: x64
|
|
||||||
- name: Verify Go
|
|
||||||
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@v4
|
|
||||||
|
|
||||||
- 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@v4
|
|
||||||
|
|
||||||
- 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@v4
|
|
||||||
|
|
||||||
- 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 }}
|
|
39
.github/workflows/workflow.yml
vendored
Normal file
39
.github/workflows/workflow.yml
vendored
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
name: build-test
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
pull_request:
|
||||||
|
paths-ignore:
|
||||||
|
- '**.md'
|
||||||
|
jobs:
|
||||||
|
run:
|
||||||
|
name: Run
|
||||||
|
runs-on: ${{ matrix.operating-system }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
operating-system: [ubuntu-latest, windows-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup node 16
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 16
|
||||||
|
cache: npm
|
||||||
|
|
||||||
|
- name: npm install
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: npm run format-check
|
||||||
|
|
||||||
|
- name: npm test
|
||||||
|
run: npm test
|
||||||
|
|
||||||
|
- name: audit packages
|
||||||
|
run: npm audit --audit-level=high
|
||||||
|
if: matrix.operating-system == 'ubuntu-latest'
|
@ -9,7 +9,6 @@ allowed:
|
|||||||
- mit
|
- mit
|
||||||
- cc0-1.0
|
- cc0-1.0
|
||||||
- unlicense
|
- unlicense
|
||||||
- 0bsd
|
|
||||||
|
|
||||||
reviewed:
|
reviewed:
|
||||||
npm:
|
npm:
|
BIN
.licenses/npm/@actions/cache.dep.yml
generated
BIN
.licenses/npm/@actions/cache.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/core.dep.yml
generated
BIN
.licenses/npm/@actions/core.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/exec.dep.yml
generated
BIN
.licenses/npm/@actions/exec.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/glob-0.1.2.dep.yml
generated
BIN
.licenses/npm/@actions/glob-0.1.2.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/glob-0.4.0.dep.yml
generated
BIN
.licenses/npm/@actions/glob-0.4.0.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/http-client.dep.yml
generated
BIN
.licenses/npm/@actions/http-client.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@actions/io.dep.yml
generated
BIN
.licenses/npm/@actions/io.dep.yml
generated
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.
BIN
.licenses/npm/@azure/abort-controller.dep.yml
generated
BIN
.licenses/npm/@azure/abort-controller.dep.yml
generated
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-http.dep.yml
generated
BIN
.licenses/npm/@azure/core-http.dep.yml
generated
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-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/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
BIN
.licenses/npm/@azure/ms-rest-js.dep.yml
generated
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.
BIN
.licenses/npm/@fastify/busboy.dep.yml
generated
BIN
.licenses/npm/@fastify/busboy.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@opentelemetry/api.dep.yml
generated
BIN
.licenses/npm/@opentelemetry/api.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@types/node-fetch.dep.yml
generated
BIN
.licenses/npm/@types/node-fetch.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@types/node.dep.yml
generated
BIN
.licenses/npm/@types/node.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/@types/tunnel.dep.yml
generated
BIN
.licenses/npm/@types/tunnel.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/abort-controller.dep.yml
generated
BIN
.licenses/npm/abort-controller.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/asynckit.dep.yml
generated
BIN
.licenses/npm/asynckit.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/balanced-match.dep.yml
generated
BIN
.licenses/npm/balanced-match.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/brace-expansion.dep.yml
generated
BIN
.licenses/npm/brace-expansion.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/combined-stream.dep.yml
generated
BIN
.licenses/npm/combined-stream.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/concat-map.dep.yml
generated
BIN
.licenses/npm/concat-map.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/delayed-stream.dep.yml
generated
BIN
.licenses/npm/delayed-stream.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/event-target-shim.dep.yml
generated
BIN
.licenses/npm/event-target-shim.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/events.dep.yml
generated
BIN
.licenses/npm/events.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/form-data-2.5.1.dep.yml
generated
BIN
.licenses/npm/form-data-2.5.1.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/form-data-4.0.0.dep.yml
generated
BIN
.licenses/npm/form-data-4.0.0.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/lru-cache.dep.yml
generated
BIN
.licenses/npm/lru-cache.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/mime-db.dep.yml
generated
BIN
.licenses/npm/mime-db.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/mime-types.dep.yml
generated
BIN
.licenses/npm/mime-types.dep.yml
generated
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
BIN
.licenses/npm/node-fetch.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/process.dep.yml
generated
BIN
.licenses/npm/process.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/sax.dep.yml
generated
BIN
.licenses/npm/sax.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/semver-7.6.0.dep.yml
generated
BIN
.licenses/npm/semver-7.6.0.dep.yml
generated
Binary file not shown.
Binary file not shown.
BIN
.licenses/npm/tr46.dep.yml
generated
BIN
.licenses/npm/tr46.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/tslib-1.14.1.dep.yml
generated
BIN
.licenses/npm/tslib-1.14.1.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/tslib-2.6.2.dep.yml
generated
BIN
.licenses/npm/tslib-2.6.2.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/undici-types.dep.yml
generated
BIN
.licenses/npm/undici-types.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/undici.dep.yml
generated
BIN
.licenses/npm/undici.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/uuid-8.3.2.dep.yml
generated
BIN
.licenses/npm/uuid-8.3.2.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
BIN
.licenses/npm/webidl-conversions.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/whatwg-url.dep.yml
generated
BIN
.licenses/npm/whatwg-url.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/xml2js.dep.yml
generated
BIN
.licenses/npm/xml2js.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
BIN
.licenses/npm/xmlbuilder.dep.yml
generated
Binary file not shown.
BIN
.licenses/npm/yallist.dep.yml
generated
BIN
.licenses/npm/yallist.dep.yml
generated
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"
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
* @actions/setup-actions-team
|
* @actions/spark
|
||||||
|
@ -55,7 +55,7 @@ a project may be further defined and clarified by project maintainers.
|
|||||||
## Enforcement
|
## Enforcement
|
||||||
|
|
||||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
reported by contacting the project team at opensource+actions/setup-go@github.com. All
|
reported by contacting the project team at opensource@github.com. All
|
||||||
complaints will be reviewed and investigated and will result in a response that
|
complaints will be reviewed and investigated and will result in a response that
|
||||||
is deemed necessary and appropriate to the circumstances. The project team is
|
is deemed necessary and appropriate to the circumstances. The project team is
|
||||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||||
@ -73,4 +73,4 @@ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.ht
|
|||||||
[homepage]: https://www.contributor-covenant.org
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
For answers to common questions about this code of conduct, see
|
For answers to common questions about this code of conduct, see
|
||||||
https://www.contributor-covenant.org/faq
|
https://www.contributor-covenant.org/faq
|
248
README.md
248
README.md
@ -1,96 +1,44 @@
|
|||||||
# setup-go
|
# setup-go
|
||||||
|
|
||||||
[![Basic validation](https://github.com/actions/setup-go/actions/workflows/basic-validation.yml/badge.svg)](https://github.com/actions/setup-go/actions/workflows/basic-validation.yml)
|
<p align="left">
|
||||||
[![Validate 'setup-go'](https://github.com/actions/setup-go/actions/workflows/versions.yml/badge.svg)](https://github.com/actions/setup-go/actions/workflows/versions.yml)
|
<a href="https://github.com/actions/setup-go/actions"><img alt="GitHub Actions status" src="https://github.com/actions/setup-go/workflows/build-test/badge.svg"></a>
|
||||||
|
|
||||||
|
<a href="https://github.com/actions/setup-go/actions"><img alt="versions status" src="https://github.com/actions/setup-go/workflows/go-versions/badge.svg"></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
This action sets up a go environment for use in 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 to `PATH`.
|
- optionally downloading and caching a version of Go by version and adding to PATH
|
||||||
- Registering problem matchers for error output.
|
- registering problem matchers for error output
|
||||||
|
|
||||||
# V5
|
# V2
|
||||||
|
|
||||||
The V5 edition of the action offers:
|
The V2 offers:
|
||||||
|
- Adds GOBIN to the PATH
|
||||||
- Upgraded Node.js runtime from node16 to node20
|
- Proxy Support
|
||||||
|
- stable input
|
||||||
See full release notes on the [releases page](https://github.com/actions/setup-go/releases).
|
|
||||||
|
|
||||||
# V4
|
|
||||||
|
|
||||||
The V4 edition of the action offers:
|
|
||||||
|
|
||||||
- Enabled caching by default
|
|
||||||
|
|
||||||
The action will try to enable caching unless the `cache` input is explicitly set to false.
|
|
||||||
|
|
||||||
Please see "[Caching dependency files and build outputs](https://github.com/actions/setup-go#caching-dependency-files-and-build-outputs)" for more information.
|
|
||||||
|
|
||||||
# V3
|
|
||||||
|
|
||||||
The V3 edition of the action offers:
|
|
||||||
|
|
||||||
- Adds `GOBIN` to the `PATH`
|
|
||||||
- Proxy support
|
|
||||||
- Check latest version
|
|
||||||
- Caching packages dependencies
|
|
||||||
- stable and oldstable aliases
|
|
||||||
- Bug Fixes (including issues around version matching and semver)
|
- Bug Fixes (including issues around version matching and semver)
|
||||||
|
|
||||||
The action will first check the local cache for a version match. If a version is not found locally, it will pull it from
|
It will first check the local cache for a version match. If version is not found locally, It will pull it from `main` branch of [go-versions](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository and on miss or failure, it will fall back to the previous behavior of download directly from [go dist](https://storage.googleapis.com/golang).
|
||||||
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).
|
|
||||||
|
|
||||||
**Note:** The `setup-go` action uses executable binaries which are built by Golang side. The action does not build
|
|
||||||
golang from source code.
|
|
||||||
|
|
||||||
Matching by [semver spec](https://github.com/npm/node-semver):
|
Matching by [semver spec](https://github.com/npm/node-semver):
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: '^1.13.1' # 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
|
- run: go version
|
||||||
```
|
```
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '>=1.17.0'
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
> **Note**: Due to the peculiarities of YAML parsing, it is recommended to wrap the version in single quotation marks:
|
|
||||||
>
|
|
||||||
> ```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.
|
|
||||||
|
|
||||||
Matching an unstable pre-release:
|
Matching an unstable pre-release:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: '1.18.0-rc.1' # The Go version to download (if necessary) and use.
|
stable: 'false'
|
||||||
- run: go version
|
go-version: '1.14.0-rc1' # The Go version to download (if necessary) and use.
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.16.0-beta.1' # The Go version to download (if necessary) and use.
|
|
||||||
- run: go version
|
- run: go version
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -98,121 +46,17 @@ steps:
|
|||||||
|
|
||||||
See [action.yml](action.yml)
|
See [action.yml](action.yml)
|
||||||
|
|
||||||
## Basic
|
Basic:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@master
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: '1.16.1' # The Go version to download (if necessary) and use.
|
go-version: '1.9.3' # The Go version to download (if necessary) and use.
|
||||||
- run: go run hello.go
|
- run: go run hello.go
|
||||||
```
|
```
|
||||||
|
|
||||||
## Check latest version
|
Matrix Testing:
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
> Setting `check-latest` to `true` has performance implications as downloading Go versions is slower than using cached
|
|
||||||
> versions.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
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@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: 'stable'
|
|
||||||
- run: go run hello.go
|
|
||||||
```
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
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 [toolkit/cache](https://github.com/actions/toolkit/tree/main/packages/cache) under the hood but requires less configuration settings.
|
|
||||||
The `cache` input is optional, and caching is turned on 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. The input supports glob patterns.
|
|
||||||
|
|
||||||
If some problem that prevents success caching happens then the action issues the warning in the log and continues the execution of the pipeline.
|
|
||||||
|
|
||||||
**Caching in monorepos**
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.17'
|
|
||||||
check-latest: true
|
|
||||||
cache-dependency-path: |
|
|
||||||
subdir/go.sum
|
|
||||||
tools/go.sum
|
|
||||||
# cache-dependency-path: "**/*.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.
|
|
||||||
|
|
||||||
The `go` directive in `go.mod` can specify a patch version or omit it altogether (e.g., `go 1.22.0` or `go 1.22`).
|
|
||||||
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://golang.org/dl/?mode=json&include=all), in that order.
|
|
||||||
|
|
||||||
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@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version-file: 'path/to/go.mod'
|
|
||||||
- run: go version
|
|
||||||
```
|
|
||||||
|
|
||||||
## Matrix testing
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@ -222,50 +66,20 @@ jobs:
|
|||||||
go: [ '1.14', '1.13' ]
|
go: [ '1.14', '1.13' ]
|
||||||
name: Go ${{ matrix.go }} sample
|
name: Go ${{ matrix.go }} sample
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
- name: Setup go
|
- name: Setup go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
- run: go run hello.go
|
- run: go run hello.go
|
||||||
```
|
```
|
||||||
|
|
||||||
### Supported version syntax
|
### Supported version syntax
|
||||||
|
|
||||||
The `go-version` input supports the following syntax:
|
The `go-version` input supports the following syntax:
|
||||||
|
|
||||||
- Specific versions: `1.15`, `1.16.1`, `1.17.0-rc.2`, `1.16.0-beta.1`
|
Specific versions: `1.15`, `1.16.1`, `1.17.0-rc2`, `1.16.0-beta1`
|
||||||
- SemVer's version range syntax: `^1.13.1`, `>=1.18.0-rc.1`
|
SemVer's version range syntax: `^1.13.1`
|
||||||
|
For more information about semantic versioning please refer [semver](https://github.com/npm/node-semver) documentation
|
||||||
For more information about semantic versioning, please refer to [semver](https://github.com/npm/node-semver)
|
|
||||||
documentation.
|
|
||||||
|
|
||||||
## Using `setup-go` on GHES
|
|
||||||
|
|
||||||
`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.
|
|
||||||
|
|
||||||
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:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GH_DOTCOM_TOKEN }}
|
|
||||||
go-version: '1.18'
|
|
||||||
```
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
@ -273,8 +87,8 @@ The scripts and documentation in this project are released under the [MIT Licens
|
|||||||
|
|
||||||
# Contributions
|
# Contributions
|
||||||
|
|
||||||
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
Contributions are welcome! See [Contributor's Guide](docs/contributors.md)
|
||||||
|
|
||||||
## Code of Conduct
|
## Code of Conduct
|
||||||
|
|
||||||
:wave: Be nice. See [our code of conduct](CODE_OF_CONDUCT.md)
|
:wave: Be nice. See [our code of conduct](CONDUCT)
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
import * as cache from '@actions/cache';
|
|
||||||
import * as core from '@actions/core';
|
|
||||||
import * as glob from '@actions/glob';
|
|
||||||
|
|
||||||
import * as cacheRestore from '../src/cache-restore';
|
|
||||||
import * as cacheUtils from '../src/cache-utils';
|
|
||||||
import {PackageManagerInfo} from '../src/package-managers';
|
|
||||||
|
|
||||||
describe('restoreCache', () => {
|
|
||||||
//Arrange
|
|
||||||
const hashFilesSpy = jest.spyOn(glob, 'hashFiles');
|
|
||||||
const getCacheDirectoryPathSpy = jest.spyOn(
|
|
||||||
cacheUtils,
|
|
||||||
'getCacheDirectoryPath'
|
|
||||||
);
|
|
||||||
const restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
|
|
||||||
const infoSpy = jest.spyOn(core, 'info');
|
|
||||||
const setOutputSpy = jest.spyOn(core, 'setOutput');
|
|
||||||
|
|
||||||
const versionSpec = '1.13.1';
|
|
||||||
const packageManager = 'default';
|
|
||||||
const cacheDependencyPath = 'path';
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
getCacheDirectoryPathSpy.mockImplementation(
|
|
||||||
(PackageManager: PackageManagerInfo) => {
|
|
||||||
return new Promise<string[]>(resolve => {
|
|
||||||
resolve(['cache_directory_path', 'cache_directory_path']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw if dependency file path is not valid', async () => {
|
|
||||||
//Arrange
|
|
||||||
hashFilesSpy.mockImplementation((somePath: string) => {
|
|
||||||
return new Promise<string>(resolve => {
|
|
||||||
resolve('');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
await expect(async () => {
|
|
||||||
await cacheRestore.restoreCache(
|
|
||||||
versionSpec,
|
|
||||||
packageManager,
|
|
||||||
cacheDependencyPath
|
|
||||||
);
|
|
||||||
}).rejects.toThrow(
|
|
||||||
'Some specified paths were not resolved, unable to cache dependencies.'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should inform if cache hit is not occured', async () => {
|
|
||||||
//Arrange
|
|
||||||
hashFilesSpy.mockImplementation((somePath: string) => {
|
|
||||||
return new Promise<string>(resolve => {
|
|
||||||
resolve('file_hash');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
restoreCacheSpy.mockImplementation(() => {
|
|
||||||
return new Promise<string>(resolve => {
|
|
||||||
resolve('');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
await cacheRestore.restoreCache(
|
|
||||||
versionSpec,
|
|
||||||
packageManager,
|
|
||||||
cacheDependencyPath
|
|
||||||
);
|
|
||||||
expect(infoSpy).toHaveBeenCalledWith(`Cache is not found`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set output if cache hit is occured', async () => {
|
|
||||||
//Arrange
|
|
||||||
hashFilesSpy.mockImplementation((somePath: string) => {
|
|
||||||
return new Promise<string>(resolve => {
|
|
||||||
resolve('file_hash');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
restoreCacheSpy.mockImplementation(() => {
|
|
||||||
return new Promise<string>(resolve => {
|
|
||||||
resolve('cache_key');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
await cacheRestore.restoreCache(
|
|
||||||
versionSpec,
|
|
||||||
packageManager,
|
|
||||||
cacheDependencyPath
|
|
||||||
);
|
|
||||||
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,211 +0,0 @@
|
|||||||
import * as exec from '@actions/exec';
|
|
||||||
import * as cache from '@actions/cache';
|
|
||||||
import * as core from '@actions/core';
|
|
||||||
import * as cacheUtils from '../src/cache-utils';
|
|
||||||
import {PackageManagerInfo} from '../src/package-managers';
|
|
||||||
|
|
||||||
describe('getCommandOutput', () => {
|
|
||||||
//Arrange
|
|
||||||
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
|
||||||
|
|
||||||
it('should return trimmed stdout in case of successful exit code', async () => {
|
|
||||||
//Arrange
|
|
||||||
const stdoutResult = ' stdout ';
|
|
||||||
const trimmedStdout = stdoutResult.trim();
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation((commandLine: string) => {
|
|
||||||
return new Promise<exec.ExecOutput>(resolve => {
|
|
||||||
resolve({exitCode: 0, stdout: stdoutResult, stderr: ''});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
return cacheUtils
|
|
||||||
.getCommandOutput('command')
|
|
||||||
.then(data => expect(data).toBe(trimmedStdout));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return error in case of unsuccessful exit code', async () => {
|
|
||||||
//Arrange
|
|
||||||
const stderrResult = 'error message';
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementation((commandLine: string) => {
|
|
||||||
return new Promise<exec.ExecOutput>(resolve => {
|
|
||||||
resolve({exitCode: 10, stdout: '', stderr: stderrResult});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
await expect(async () => {
|
|
||||||
await cacheUtils.getCommandOutput('command');
|
|
||||||
}).rejects.toThrow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getPackageManagerInfo', () => {
|
|
||||||
it('should return package manager info in case of valid package manager name', async () => {
|
|
||||||
//Arrange
|
|
||||||
const packageManagerName = 'default';
|
|
||||||
const expectedResult = {
|
|
||||||
dependencyFilePattern: 'go.sum',
|
|
||||||
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
|
||||||
};
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
return cacheUtils
|
|
||||||
.getPackageManagerInfo(packageManagerName)
|
|
||||||
.then(data => expect(data).toEqual(expectedResult));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw the error in case of invalid package manager name', async () => {
|
|
||||||
//Arrange
|
|
||||||
const packageManagerName = 'invalidName';
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
await expect(async () => {
|
|
||||||
await cacheUtils.getPackageManagerInfo(packageManagerName);
|
|
||||||
}).rejects.toThrow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getCacheDirectoryPath', () => {
|
|
||||||
//Arrange
|
|
||||||
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
|
|
||||||
|
|
||||||
const validPackageManager: PackageManagerInfo = {
|
|
||||||
dependencyFilePattern: 'go.sum',
|
|
||||||
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
|
||||||
};
|
|
||||||
|
|
||||||
it('should return path to the cache folders which specified package manager uses', async () => {
|
|
||||||
//Arrange
|
|
||||||
getExecOutputSpy.mockImplementation((commandLine: string) => {
|
|
||||||
return new Promise<exec.ExecOutput>(resolve => {
|
|
||||||
resolve({exitCode: 0, stdout: 'path/to/cache/folder', stderr: ''});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const expectedResult = ['path/to/cache/folder', 'path/to/cache/folder'];
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
return cacheUtils
|
|
||||||
.getCacheDirectoryPath(validPackageManager)
|
|
||||||
.then(data => expect(data).toEqual(expectedResult));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return path to the cache folder if one command return empty str', async () => {
|
|
||||||
//Arrange
|
|
||||||
getExecOutputSpy.mockImplementationOnce((commandLine: string) => {
|
|
||||||
return new Promise<exec.ExecOutput>(resolve => {
|
|
||||||
resolve({exitCode: 0, stdout: 'path/to/cache/folder', stderr: ''});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
getExecOutputSpy.mockImplementationOnce((commandLine: string) => {
|
|
||||||
return new Promise<exec.ExecOutput>(resolve => {
|
|
||||||
resolve({exitCode: 0, stdout: '', stderr: ''});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
const expectedResult = ['path/to/cache/folder'];
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
return cacheUtils
|
|
||||||
.getCacheDirectoryPath(validPackageManager)
|
|
||||||
.then(data => expect(data).toEqual(expectedResult));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw if the both commands return empty str', async () => {
|
|
||||||
getExecOutputSpy.mockImplementation((commandLine: string) => {
|
|
||||||
return new Promise<exec.ExecOutput>(resolve => {
|
|
||||||
resolve({exitCode: 10, stdout: '', stderr: ''});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
await expect(async () => {
|
|
||||||
await cacheUtils.getCacheDirectoryPath(validPackageManager);
|
|
||||||
}).rejects.toThrow();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw if the specified package name is invalid', async () => {
|
|
||||||
getExecOutputSpy.mockImplementation((commandLine: string) => {
|
|
||||||
return new Promise<exec.ExecOutput>(resolve => {
|
|
||||||
resolve({exitCode: 10, stdout: '', stderr: 'Error message'});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
await expect(async () => {
|
|
||||||
await cacheUtils.getCacheDirectoryPath(validPackageManager);
|
|
||||||
}).rejects.toThrow();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('isCacheFeatureAvailable', () => {
|
|
||||||
//Arrange
|
|
||||||
const isFeatureAvailableSpy = jest.spyOn(cache, 'isFeatureAvailable');
|
|
||||||
const warningSpy = jest.spyOn(core, 'warning');
|
|
||||||
|
|
||||||
it('should return true when cache feature is available', () => {
|
|
||||||
//Arrange
|
|
||||||
isFeatureAvailableSpy.mockImplementation(() => {
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
//Act
|
|
||||||
const functionResult = cacheUtils.isCacheFeatureAvailable();
|
|
||||||
|
|
||||||
//Assert
|
|
||||||
expect(functionResult).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should warn when cache feature is unavailable and GHES is not used', () => {
|
|
||||||
//Arrange
|
|
||||||
isFeatureAvailableSpy.mockImplementation(() => {
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
|
|
||||||
|
|
||||||
const warningMessage =
|
|
||||||
'The runner was not able to contact the cache service. Caching will be skipped';
|
|
||||||
|
|
||||||
//Act
|
|
||||||
cacheUtils.isCacheFeatureAvailable();
|
|
||||||
|
|
||||||
//Assert
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false when cache feature is unavailable', () => {
|
|
||||||
//Arrange
|
|
||||||
isFeatureAvailableSpy.mockImplementation(() => {
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://github.com';
|
|
||||||
|
|
||||||
//Act
|
|
||||||
const functionResult = cacheUtils.isCacheFeatureAvailable();
|
|
||||||
|
|
||||||
//Assert
|
|
||||||
expect(functionResult).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should warn when cache feature is unavailable and GHES is used', () => {
|
|
||||||
//Arrange
|
|
||||||
isFeatureAvailableSpy.mockImplementation(() => {
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
process.env['GITHUB_SERVER_URL'] = 'https://nongithub.com';
|
|
||||||
|
|
||||||
const 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.';
|
|
||||||
|
|
||||||
//Act + Assert
|
|
||||||
expect(cacheUtils.isCacheFeatureAvailable()).toBeFalsy();
|
|
||||||
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,12 +0,0 @@
|
|||||||
module example.com/mymodule
|
|
||||||
|
|
||||||
go 1.20
|
|
||||||
|
|
||||||
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
|
|
@ -1,3 +0,0 @@
|
|||||||
go 1.21
|
|
||||||
|
|
||||||
use .
|
|
@ -1,29 +1,4 @@
|
|||||||
[
|
[
|
||||||
{
|
|
||||||
"version": "1.17.6",
|
|
||||||
"stable": true,
|
|
||||||
"release_url": "https://github.com/actions/go-versions/releases/tag/1.17.6-1668090892",
|
|
||||||
"files": [
|
|
||||||
{
|
|
||||||
"filename": "go-1.17.6-darwin-x64.tar.gz",
|
|
||||||
"arch": "x64",
|
|
||||||
"platform": "darwin",
|
|
||||||
"download_url": "https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-darwin-x64.tar.gz"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename": "go-1.17.6-linux-x64.tar.gz",
|
|
||||||
"arch": "x64",
|
|
||||||
"platform": "linux",
|
|
||||||
"download_url": "https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-linux-x64.tar.gz"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"filename": "go-1.17.6-win32-x64.zip",
|
|
||||||
"arch": "x64",
|
|
||||||
"platform": "win32",
|
|
||||||
"download_url": "https://github.com/actions/go-versions/releases/download/1.17.6-1668090892/go-1.17.6-win32-x64.zip"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"version": "1.12.17",
|
"version": "1.12.17",
|
||||||
"stable": true,
|
"stable": true,
|
||||||
|
@ -3,64 +3,48 @@ 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 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;
|
|
||||||
const posixJoin = path.posix.join;
|
|
||||||
|
|
||||||
jest.setTimeout(10000);
|
|
||||||
|
|
||||||
describe('setup-go', () => {
|
describe('setup-go', () => {
|
||||||
let inputs = {} as any;
|
let inputs = {} as any;
|
||||||
let os = {} as any;
|
let os = {} as any;
|
||||||
|
|
||||||
let inSpy: jest.SpyInstance;
|
let inSpy: jest.SpyInstance;
|
||||||
let getBooleanInputSpy: jest.SpyInstance;
|
|
||||||
let exportVarSpy: jest.SpyInstance;
|
|
||||||
let findSpy: jest.SpyInstance;
|
let findSpy: jest.SpyInstance;
|
||||||
let cnSpy: jest.SpyInstance;
|
let cnSpy: jest.SpyInstance;
|
||||||
let logSpy: jest.SpyInstance;
|
let logSpy: jest.SpyInstance;
|
||||||
let getSpy: jest.SpyInstance;
|
let getSpy: jest.SpyInstance;
|
||||||
let platSpy: jest.SpyInstance;
|
let platSpy: jest.SpyInstance;
|
||||||
let archSpy: jest.SpyInstance;
|
let archSpy: jest.SpyInstance;
|
||||||
let joinSpy: jest.SpyInstance;
|
|
||||||
let dlSpy: jest.SpyInstance;
|
let dlSpy: jest.SpyInstance;
|
||||||
let extractTarSpy: jest.SpyInstance;
|
let exSpy: jest.SpyInstance;
|
||||||
let extractZipSpy: jest.SpyInstance;
|
|
||||||
let cacheSpy: jest.SpyInstance;
|
let cacheSpy: jest.SpyInstance;
|
||||||
let dbgSpy: jest.SpyInstance;
|
let dbgSpy: jest.SpyInstance;
|
||||||
let whichSpy: jest.SpyInstance;
|
let whichSpy: jest.SpyInstance;
|
||||||
let existsSpy: jest.SpyInstance;
|
let existsSpy: 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;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(() => {
|
||||||
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_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
|
||||||
}, 100000);
|
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
|
|
||||||
|
|
||||||
// @actions/core
|
// @actions/core
|
||||||
inputs = {};
|
inputs = {};
|
||||||
inSpy = jest.spyOn(core, 'getInput');
|
inSpy = jest.spyOn(core, 'getInput');
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
inSpy.mockImplementation(name => inputs[name]);
|
||||||
getBooleanInputSpy = jest.spyOn(core, 'getBooleanInput');
|
|
||||||
getBooleanInputSpy.mockImplementation(name => inputs[name]);
|
|
||||||
exportVarSpy = jest.spyOn(core, 'exportVariable');
|
|
||||||
|
|
||||||
// node
|
// node
|
||||||
os = {};
|
os = {};
|
||||||
@ -70,37 +54,19 @@ describe('setup-go', () => {
|
|||||||
archSpy.mockImplementation(() => os['arch']);
|
archSpy.mockImplementation(() => os['arch']);
|
||||||
execSpy = jest.spyOn(cp, 'execSync');
|
execSpy = jest.spyOn(cp, 'execSync');
|
||||||
|
|
||||||
// switch path join behaviour based on set os.platform
|
|
||||||
joinSpy = jest.spyOn(path, 'join');
|
|
||||||
joinSpy.mockImplementation((...paths: string[]): string => {
|
|
||||||
if (os['platform'] == 'win32') {
|
|
||||||
return win32Join(...paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
return posixJoin(...paths);
|
|
||||||
});
|
|
||||||
|
|
||||||
// @actions/tool-cache
|
// @actions/tool-cache
|
||||||
findSpy = jest.spyOn(tc, 'find');
|
findSpy = jest.spyOn(tc, 'find');
|
||||||
dlSpy = jest.spyOn(tc, 'downloadTool');
|
dlSpy = jest.spyOn(tc, 'downloadTool');
|
||||||
extractTarSpy = jest.spyOn(tc, 'extractTar');
|
exSpy = jest.spyOn(tc, 'extractTar');
|
||||||
extractZipSpy = jest.spyOn(tc, 'extractZip');
|
|
||||||
cacheSpy = jest.spyOn(tc, 'cacheDir');
|
cacheSpy = jest.spyOn(tc, 'cacheDir');
|
||||||
getSpy = jest.spyOn(im, 'getVersionsDist');
|
getSpy = jest.spyOn(im, 'getVersionsDist');
|
||||||
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
|
getManifestSpy = jest.spyOn(tc, 'getManifestFromRepo');
|
||||||
getAllVersionsSpy = jest.spyOn(im, 'getManifest');
|
|
||||||
|
|
||||||
// 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');
|
|
||||||
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);
|
||||||
|
|
||||||
@ -115,7 +81,7 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
logSpy.mockImplementation(line => {
|
logSpy.mockImplementation(line => {
|
||||||
// uncomment to debug
|
// uncomment to debug
|
||||||
//process.stderr.write('log:' + line + '\n');
|
// process.stderr.write('log:' + line + '\n');
|
||||||
});
|
});
|
||||||
dbgSpy.mockImplementation(msg => {
|
dbgSpy.mockImplementation(msg => {
|
||||||
// uncomment to see debug output
|
// uncomment to see debug output
|
||||||
@ -124,25 +90,20 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
//jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
//jest.restoreAllMocks();
|
//jest.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
jest.restoreAllMocks();
|
console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions
|
||||||
}, 100000);
|
}, 100000);
|
||||||
|
|
||||||
it('can extract the major.minor.patch version from a given Go version string', async () => {
|
|
||||||
const goVersionOutput = 'go version go1.16.6 darwin/amd64';
|
|
||||||
expect(main.parseGoVersion(goVersionOutput)).toBe('1.16.6');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('can find 1.9.7 from manifest on osx', async () => {
|
it('can find 1.9.7 from manifest on osx', async () => {
|
||||||
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');
|
||||||
@ -155,7 +116,7 @@ describe('setup-go', () => {
|
|||||||
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');
|
||||||
@ -168,7 +129,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');
|
||||||
@ -182,11 +143,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', true);
|
||||||
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');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -195,11 +156,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', true);
|
||||||
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');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -208,11 +169,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', true);
|
||||||
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');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -221,11 +182,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', true);
|
||||||
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');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -234,11 +195,14 @@ 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-rc1',
|
||||||
|
false
|
||||||
|
);
|
||||||
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');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -246,11 +210,11 @@ 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();
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Setup go version spec 1.13.0`);
|
expect(logSpy).toHaveBeenCalledWith(`Setup go stable version spec 1.13.0`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('evaluates to stable with no input', async () => {
|
it('evaluates to stable with no input', async () => {
|
||||||
@ -258,69 +222,36 @@ 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 stable version spec 1.13.0`);
|
||||||
});
|
|
||||||
|
|
||||||
it('does not export any variables for Go versions >=1.9', async () => {
|
|
||||||
inputs['go-version'] = '1.13.0';
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
|
|
||||||
const toolPath = path.normalize('/cache/go/1.13.0/x64');
|
|
||||||
findSpy.mockImplementation(() => toolPath);
|
|
||||||
|
|
||||||
const vars: {[key: string]: string} = {};
|
|
||||||
exportVarSpy.mockImplementation((name: string, val: string) => {
|
|
||||||
vars[name] = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
expect(vars).toStrictEqual({});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('exports GOROOT for Go versions <1.9', async () => {
|
|
||||||
inputs['go-version'] = '1.8';
|
|
||||||
inSpy.mockImplementation(name => inputs[name]);
|
|
||||||
|
|
||||||
const toolPath = path.normalize('/cache/go/1.8.0/x64');
|
|
||||||
findSpy.mockImplementation(() => toolPath);
|
|
||||||
|
|
||||||
const vars: {[key: string]: string} = {};
|
|
||||||
exportVarSpy.mockImplementation((name: string, val: string) => {
|
|
||||||
vars[name] = val;
|
|
||||||
});
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
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();
|
||||||
|
|
||||||
|
let expPath = path.join(toolPath, 'bin');
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
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(() => {
|
||||||
@ -338,40 +269,15 @@ 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');
|
exSpy.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(exSpy).toHaveBeenCalled();
|
||||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('downloads a version not in the cache (windows)', async () => {
|
|
||||||
os.platform = 'win32';
|
|
||||||
os.arch = 'x64';
|
|
||||||
|
|
||||||
inputs['go-version'] = '1.13.1';
|
|
||||||
process.env['RUNNER_TEMP'] = 'C:\\temp\\';
|
|
||||||
|
|
||||||
findSpy.mockImplementation(() => '');
|
|
||||||
dlSpy.mockImplementation(() => 'C:\\temp\\some\\path');
|
|
||||||
extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path');
|
|
||||||
|
|
||||||
const toolPath = path.normalize('C:\\cache\\go\\1.13.0\\x64');
|
|
||||||
cacheSpy.mockImplementation(() => toolPath);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
const expPath = path.win32.join(toolPath, 'bin');
|
|
||||||
expect(dlSpy).toHaveBeenCalledWith(
|
|
||||||
'https://storage.googleapis.com/golang/go1.13.1.windows-amd64.zip',
|
|
||||||
'C:\\temp\\go1.13.1.windows-amd64.zip',
|
|
||||||
undefined
|
|
||||||
);
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -393,28 +299,29 @@ describe('setup-go', () => {
|
|||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const versionSpec = '1.12.16';
|
// a version which is in the manifest
|
||||||
|
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');
|
exSpy.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(exSpy).toHaveBeenCalled();
|
||||||
expect(logSpy).not.toHaveBeenCalledWith(
|
expect(logSpy).not.toHaveBeenCalledWith(
|
||||||
'Not found in manifest. Falling back to download directly from Go'
|
'Not found in manifest. Falling back to download directly from Go'
|
||||||
);
|
);
|
||||||
@ -430,28 +337,29 @@ describe('setup-go', () => {
|
|||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const versionSpec = '1.12';
|
// a version which is in the manifest
|
||||||
|
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');
|
exSpy.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(exSpy).toHaveBeenCalled();
|
||||||
expect(logSpy).not.toHaveBeenCalledWith(
|
expect(logSpy).not.toHaveBeenCalledWith(
|
||||||
'Not found in manifest. Falling back to download directly from Go'
|
'Not found in manifest. Falling back to download directly from Go'
|
||||||
);
|
);
|
||||||
@ -463,32 +371,36 @@ describe('setup-go', () => {
|
|||||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('falls back to a version from go dist', async () => {
|
it('falls back to a version from node dist', async () => {
|
||||||
os.platform = 'linux';
|
os.platform = 'linux';
|
||||||
os.arch = 'x64';
|
os.arch = 'x64';
|
||||||
|
|
||||||
const versionSpec = '1.12.14';
|
// a version which is not in the manifest but is in node dist
|
||||||
|
let versionSpec = '1.12.14';
|
||||||
|
|
||||||
inputs['go-version'] = versionSpec;
|
inputs['go-version'] = versionSpec;
|
||||||
inputs['token'] = 'faketoken';
|
inputs['token'] = 'faketoken';
|
||||||
|
|
||||||
|
let expectedUrl =
|
||||||
|
'https://github.com/actions/go-versions/releases/download/1.12.14-20200616.18/go-1.12.14-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.14/x64');
|
let toolPath = path.normalize('/cache/go/1.12.14/x64');
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
exSpy.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 stable 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...');
|
||||||
expect(dlSpy).toHaveBeenCalled();
|
expect(dlSpy).toHaveBeenCalled();
|
||||||
expect(logSpy).toHaveBeenCalledWith('matching 1.12.14...');
|
expect(logSpy).toHaveBeenCalledWith('matching 1.12.14...');
|
||||||
expect(extractTarSpy).toHaveBeenCalled();
|
expect(exSpy).toHaveBeenCalled();
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
expect(logSpy).toHaveBeenCalledWith(
|
||||||
'Not found in manifest. Falling back to download directly from Go'
|
'Not found in manifest. Falling back to download directly from Go'
|
||||||
);
|
);
|
||||||
@ -498,7 +410,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';
|
||||||
|
|
||||||
@ -519,7 +431,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();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -533,12 +445,12 @@ describe('setup-go', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mkdirpSpy.mockImplementation(async () => {});
|
mkdirpSpy.mockImplementation(async () => {});
|
||||||
existsSpy.mockImplementation(() => {
|
existsSpy.mockImplementation(path => {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
const added = await main.addBinToPath();
|
let added = await main.addBinToPath();
|
||||||
expect(added).toBeTruthy();
|
expect(added).toBeTruthy;
|
||||||
});
|
});
|
||||||
|
|
||||||
interface Annotation {
|
interface Annotation {
|
||||||
@ -552,9 +464,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);
|
||||||
@ -566,8 +478,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);
|
||||||
@ -576,8 +488,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);
|
||||||
@ -586,8 +498,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);
|
||||||
@ -596,8 +508,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);
|
||||||
@ -606,8 +518,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);
|
||||||
@ -616,8 +528,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);
|
||||||
@ -626,8 +538,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);
|
||||||
@ -636,8 +548,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);
|
||||||
@ -647,11 +559,11 @@ describe('setup-go', () => {
|
|||||||
|
|
||||||
// 1.13.1 => 1.13.1
|
// 1.13.1 => 1.13.1
|
||||||
// 1.13 => 1.13.0
|
// 1.13 => 1.13.0
|
||||||
// 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
|
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
|
||||||
// 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
|
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
|
||||||
it('converts prerelease versions', async () => {
|
it('converts prerelease versions', async () => {
|
||||||
expect(im.makeSemver('1.10beta1')).toBe('1.10.0-beta.1');
|
expect(im.makeSemver('1.10beta1')).toBe('1.10.0-beta1');
|
||||||
expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc.1');
|
expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('converts dot zero versions', async () => {
|
it('converts dot zero versions', async () => {
|
||||||
@ -661,309 +573,4 @@ describe('setup-go', () => {
|
|||||||
it('does not convert exact versions', async () => {
|
it('does not convert exact versions', async () => {
|
||||||
expect(im.makeSemver('1.13.1')).toBe('1.13.1');
|
expect(im.makeSemver('1.13.1')).toBe('1.13.1');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('check-latest flag', () => {
|
|
||||||
it("use local version and don't check manifest if check-latest is not specified", async () => {
|
|
||||||
os.platform = 'linux';
|
|
||||||
os.arch = 'x64';
|
|
||||||
|
|
||||||
inputs['go-version'] = '1.16';
|
|
||||||
inputs['check-latest'] = false;
|
|
||||||
|
|
||||||
const toolPath = path.normalize('/cache/go/1.16.1/x64');
|
|
||||||
findSpy.mockReturnValue(toolPath);
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
|
||||||
expect(logSpy).not.toHaveBeenCalledWith(
|
|
||||||
'Attempting to resolve the latest version from the manifest...'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('check latest version and resolve it from local cache', async () => {
|
|
||||||
os.platform = 'linux';
|
|
||||||
os.arch = 'x64';
|
|
||||||
|
|
||||||
inputs['go-version'] = '1.16';
|
|
||||||
inputs['check-latest'] = true;
|
|
||||||
|
|
||||||
const toolPath = path.normalize('/cache/go/1.16.1/x64');
|
|
||||||
findSpy.mockReturnValue(toolPath);
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.16');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('check latest version and install it from manifest', async () => {
|
|
||||||
os.platform = 'linux';
|
|
||||||
os.arch = 'x64';
|
|
||||||
|
|
||||||
const versionSpec = '1.17';
|
|
||||||
const patchVersion = '1.17.6';
|
|
||||||
inputs['go-version'] = versionSpec;
|
|
||||||
inputs['stable'] = 'true';
|
|
||||||
inputs['check-latest'] = true;
|
|
||||||
|
|
||||||
findSpy.mockImplementation(() => '');
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
|
||||||
const toolPath = path.normalize('/cache/go/1.17.6/x64');
|
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Setup go version spec ${versionSpec}`
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
'Attempting to resolve the latest version from the manifest...'
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(`Resolved as '${patchVersion}'`);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Attempting to download ${patchVersion}...`
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Extracting Go...');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Adding to the cache ...');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Added go to the path');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Successfully set up Go version ${versionSpec}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fallback to dist if version is not found in manifest', async () => {
|
|
||||||
os.platform = 'linux';
|
|
||||||
os.arch = 'x64';
|
|
||||||
|
|
||||||
const versionSpec = '1.13';
|
|
||||||
|
|
||||||
inputs['go-version'] = versionSpec;
|
|
||||||
inputs['check-latest'] = true;
|
|
||||||
inputs['always-auth'] = false;
|
|
||||||
inputs['token'] = 'faketoken';
|
|
||||||
|
|
||||||
// ... but not in the local cache
|
|
||||||
findSpy.mockImplementation(() => '');
|
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
|
||||||
const toolPath = path.normalize('/cache/go/1.13.7/x64');
|
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
|
||||||
|
|
||||||
expect(dlSpy).toHaveBeenCalled();
|
|
||||||
expect(extractTarSpy).toHaveBeenCalled();
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
'Attempting to resolve the latest version from the manifest...'
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Failed to resolve version ${versionSpec} from manifest`
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Attempting to download ${versionSpec}...`
|
|
||||||
);
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('fallback to dist if manifest is not available', async () => {
|
|
||||||
os.platform = 'linux';
|
|
||||||
os.arch = 'x64';
|
|
||||||
|
|
||||||
const versionSpec = '1.13';
|
|
||||||
|
|
||||||
process.env['GITHUB_PATH'] = '';
|
|
||||||
|
|
||||||
inputs['go-version'] = versionSpec;
|
|
||||||
inputs['check-latest'] = true;
|
|
||||||
inputs['always-auth'] = false;
|
|
||||||
inputs['token'] = 'faketoken';
|
|
||||||
|
|
||||||
// ... but not in the local cache
|
|
||||||
findSpy.mockImplementation(() => '');
|
|
||||||
getManifestSpy.mockImplementation(() => {
|
|
||||||
throw new Error('Unable to download manifest');
|
|
||||||
});
|
|
||||||
getAllVersionsSpy.mockImplementationOnce(() => undefined);
|
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
|
||||||
const toolPath = path.normalize('/cache/go/1.13.7/x64');
|
|
||||||
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
|
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
const expPath = path.join(toolPath, 'bin');
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Failed to resolve version ${versionSpec} from manifest`
|
|
||||||
);
|
|
||||||
expect(dlSpy).toHaveBeenCalled();
|
|
||||||
expect(extractTarSpy).toHaveBeenCalled();
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
'Attempting to resolve the latest version from the manifest...'
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
'Unable to resolve a version from the manifest...'
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Failed to resolve version ${versionSpec} from manifest`
|
|
||||||
);
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Attempting to download ${versionSpec}...`
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('go-version-file', () => {
|
|
||||||
const goModContents = `module example.com/mymodule
|
|
||||||
|
|
||||||
go 1.14
|
|
||||||
|
|
||||||
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 goWorkContents = `go 1.19
|
|
||||||
|
|
||||||
use .
|
|
||||||
|
|
||||||
`;
|
|
||||||
|
|
||||||
it('reads version from go.mod', async () => {
|
|
||||||
inputs['go-version-file'] = 'go.mod';
|
|
||||||
existsSpy.mockImplementation(() => true);
|
|
||||||
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.14');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.14...');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('matching 1.14...');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reads version from go.work', async () => {
|
|
||||||
inputs['go-version-file'] = 'go.work';
|
|
||||||
existsSpy.mockImplementation(() => true);
|
|
||||||
readFileSpy.mockImplementation(() => Buffer.from(goWorkContents));
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.19');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.19...');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('matching 1.19...');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reads version from .go-version', async () => {
|
|
||||||
inputs['go-version-file'] = '.go-version';
|
|
||||||
existsSpy.mockImplementation(() => true);
|
|
||||||
readFileSpy.mockImplementation(() => Buffer.from(`1.13.0${osm.EOL}`));
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.13.0');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.13.0...');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('matching 1.13.0...');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('is overwritten by go-version', async () => {
|
|
||||||
inputs['go-version'] = '1.13.1';
|
|
||||||
inputs['go-version-file'] = 'go.mod';
|
|
||||||
existsSpy.mockImplementation(() => true);
|
|
||||||
readFileSpy.mockImplementation(() => Buffer.from(goModContents));
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Setup go version spec 1.13.1');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.13.1...');
|
|
||||||
expect(logSpy).toHaveBeenCalledWith('matching 1.13.1...');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('reports a read failure', async () => {
|
|
||||||
inputs['go-version-file'] = 'go.mod';
|
|
||||||
existsSpy.mockImplementation(() => false);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(cnSpy).toHaveBeenCalledWith(
|
|
||||||
`::error::The specified go version file at: go.mod does not exist${osm.EOL}`
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('acquires specified architecture of go', async () => {
|
|
||||||
for (const {arch, version, osSpec} of [
|
|
||||||
{arch: 'amd64', version: '1.13.7', osSpec: 'linux'},
|
|
||||||
{arch: 'armv6l', version: '1.12.2', osSpec: 'linux'}
|
|
||||||
]) {
|
|
||||||
os.platform = osSpec;
|
|
||||||
os.arch = arch;
|
|
||||||
|
|
||||||
const fileExtension = os.platform === 'win32' ? 'zip' : 'tar.gz';
|
|
||||||
|
|
||||||
const platform = os.platform === 'win32' ? 'win' : os.platform;
|
|
||||||
|
|
||||||
inputs['go-version'] = version;
|
|
||||||
inputs['architecture'] = arch;
|
|
||||||
|
|
||||||
const expectedUrl =
|
|
||||||
platform === 'win32'
|
|
||||||
? `https://github.com/actions/go-versions/releases/download/${version}/go-${version}-${platform}-${arch}.${fileExtension}`
|
|
||||||
: `https://storage.googleapis.com/golang/go${version}.${osSpec}-${arch}.${fileExtension}`;
|
|
||||||
|
|
||||||
// ... but not in the local cache
|
|
||||||
findSpy.mockImplementation(() => '');
|
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
|
||||||
const toolPath = path.normalize(`/cache/go/${version}/${arch}`);
|
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`Acquiring go${version} from ${expectedUrl}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}, 100000);
|
|
||||||
|
|
||||||
it.each(['stable', 'oldstable'])(
|
|
||||||
'acquires latest go version with %s go-version input',
|
|
||||||
async (alias: string) => {
|
|
||||||
const arch = 'x64';
|
|
||||||
os.platform = 'darwin';
|
|
||||||
os.arch = arch;
|
|
||||||
|
|
||||||
inputs['go-version'] = alias;
|
|
||||||
inputs['architecture'] = os.arch;
|
|
||||||
|
|
||||||
// ... but not in the local cache
|
|
||||||
findSpy.mockImplementation(() => '');
|
|
||||||
|
|
||||||
dlSpy.mockImplementation(async () => '/some/temp/path');
|
|
||||||
const toolPath = path.normalize(`/cache/go/${alias}/${arch}`);
|
|
||||||
cacheSpy.mockImplementation(async () => toolPath);
|
|
||||||
|
|
||||||
await main.run();
|
|
||||||
|
|
||||||
const releaseIndex = alias === 'stable' ? 0 : 1;
|
|
||||||
|
|
||||||
expect(logSpy).toHaveBeenCalledWith(
|
|
||||||
`${alias} version resolved as ${goTestManifest[releaseIndex].version}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -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')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
34
action.yml
34
action.yml
@ -1,31 +1,15 @@
|
|||||||
name: 'Setup Go environment'
|
name: 'Setup Go environment'
|
||||||
description: 'Setup a Go environment and add it to the PATH'
|
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:
|
stable:
|
||||||
description: 'Path to the go.mod or go.work file.'
|
description: 'Whether to download only stable versions'
|
||||||
check-latest:
|
default: 'true'
|
||||||
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
|
|
||||||
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.
|
||||||
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
|
default: ${{ github.token }}
|
||||||
cache:
|
|
||||||
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
|
|
||||||
default: true
|
|
||||||
cache-dependency-path:
|
|
||||||
description: 'Used to specify the path to a dependency file - go.sum'
|
|
||||||
architecture:
|
|
||||||
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
|
|
||||||
outputs:
|
|
||||||
go-version:
|
|
||||||
description: 'The installed Go version. Useful when given a version range as input.'
|
|
||||||
cache-hit:
|
|
||||||
description: 'A boolean value to indicate if a cache was hit'
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node20'
|
using: 'node16'
|
||||||
main: 'dist/setup/index.js'
|
main: 'dist/index.js'
|
||||||
post: 'dist/cache-save/index.js'
|
|
||||||
post-if: success()
|
|
||||||
|
82956
dist/cache-save/index.js
vendored
82956
dist/cache-save/index.js
vendored
File diff suppressed because one or more lines are too long
5454
dist/index.js
vendored
Normal file
5454
dist/index.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
90580
dist/setup/index.js
vendored
90580
dist/setup/index.js
vendored
File diff suppressed because one or more lines are too long
@ -1,69 +0,0 @@
|
|||||||
# 0. Caching dependencies
|
|
||||||
Date: 2022-04-13
|
|
||||||
|
|
||||||
Status: Accepted
|
|
||||||
|
|
||||||
# Context
|
|
||||||
`actions/setup-go` is the one of the most popular action related to Golang in GitHub Actions. Many customers use it in conjunction with [actions/cache](https://github.com/actions/cache) to speed up dependency installation process.
|
|
||||||
See more examples on proper usage in [actions/cache documentation](https://github.com/actions/cache/blob/main/examples.md#go---modules).
|
|
||||||
|
|
||||||
# Goals & Anti-Goals
|
|
||||||
Integration of caching functionality into `actions/setup-go` action will bring the following benefits for action users:
|
|
||||||
- Decrease the entry threshold for using the cache for Go dependencies and simplify initial configuration
|
|
||||||
- Simplify YAML pipelines because there will be no need for additional steps to enable caching
|
|
||||||
- More users will use cache for Go so more customers will have fast builds!
|
|
||||||
|
|
||||||
We don't pursue the goal to provide wide customization of caching in scope of `actions/setup-go` action. The purpose of this integration is covering ~90% of basic use-cases. If user needs flexible customization, we should advice them to use `actions/cache` directly.
|
|
||||||
|
|
||||||
# Decision
|
|
||||||
- Add `cache` input parameter to `actions/setup-go`. For now, input will accept the following values:
|
|
||||||
- `true` - enable caching for go dependencies
|
|
||||||
- `false`- disable caching for go dependencies. This value will be set as default value
|
|
||||||
- Cache feature will be disabled by default to make sure that we don't break existing customers. We will consider enabling cache by default in next major releases
|
|
||||||
- Action will try to search a go.sum files in the repository and throw error in the scenario that it was not found
|
|
||||||
- The hash of found file will be used as cache key (the same approach like [actions/cache](https://github.com/actions/cache/blob/main/examples.md#go---modules) recommends)
|
|
||||||
- The following key cache will be used `${{ runner.os }}-go${{ go-version }}-${{ hashFiles('<go.sum-path>') }}`
|
|
||||||
- Action will cache global cache from the `go env GOMODCACHE` and `go env GOCACHE` commands.
|
|
||||||
- Add a `cache-dependency-path` input parameter to `actions/setup-go`. The new input will accept an array or regex of dependency files. The field will accept a path (relative to the repository root) to dependency files. If the provided path contains wildcards, the action will search all matching files and calculate a common hash like the ${{ hashFiles('**/go.sum') }} YAML construction does.
|
|
||||||
|
|
||||||
# Example of real use-cases
|
|
||||||
|
|
||||||
- With cache
|
|
||||||
|
|
||||||
```yml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: '18'
|
|
||||||
cache: true
|
|
||||||
```
|
|
||||||
|
|
||||||
- With cache-dependency-path
|
|
||||||
|
|
||||||
```yml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: '18'
|
|
||||||
cache: true
|
|
||||||
cache-dependency-path: **/go.sum
|
|
||||||
```
|
|
||||||
|
|
||||||
```yml
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
|
||||||
go-version: '18'
|
|
||||||
cache: true
|
|
||||||
cache-dependency-path: |
|
|
||||||
**/go.sum
|
|
||||||
**/go.mod
|
|
||||||
```
|
|
||||||
|
|
||||||
# Release process
|
|
||||||
|
|
||||||
As soon as functionality is implemented, we will release minor update of action. No need to bump major version since there are no breaking changes for existing users.
|
|
||||||
After that, we will update [starter-workflows](https://github.com/actions/starter-workflows/blob/main/ci/go.yml)
|
|
@ -1,116 +1,17 @@
|
|||||||
# Contributors
|
# Contributors
|
||||||
|
|
||||||
Thank you for contributing!
|
|
||||||
|
|
||||||
We have prepared a short guide so that the process of making your contribution is as simple and clear as possible. Please check it out before you contribute!
|
# Checkin
|
||||||
|
|
||||||
## How can I contribute...
|
- Do checkin source (src)
|
||||||
|
- Do checkin build output (lib)
|
||||||
|
- Do checkin runtime node_modules
|
||||||
|
- Do not checkin
|
||||||
|
|
||||||
* [Contribute Documentation :green_book:](#contribute-documentation)
|
# Adding a dev dependency
|
||||||
|
|
||||||
* [Contribute Code :computer:](#contribute-code)
|
Remember to update .gitignore.
|
||||||
|
|
||||||
* [Provide Support on Issues :pencil:](#provide-support-on-issues)
|
# Updating toolkit dependency
|
||||||
|
|
||||||
* [Review Pull Requests :mag:](#review-pull-requests)
|
Until released publically, update tgz packages in toolkit
|
||||||
|
|
||||||
## Contribute documentation
|
|
||||||
|
|
||||||
Documentation is a super important, critical part of this project. Docs are how we keep track of what we're doing, how, and why. It's how we stay on the same page about our policies and how we tell others everything they need to be able to use this project or contribute to it.
|
|
||||||
|
|
||||||
Documentation contributions of any size are welcome! Feel free to contribute even if you're just rewording a sentence to be more clear, or fixing a spelling mistake!
|
|
||||||
|
|
||||||
**How to contribute:**
|
|
||||||
|
|
||||||
Pull requests are the easiest way to contribute changes to git repos at GitHub. They are the preferred contribution method, as they offer a nice way of commenting and amending the proposed 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
|
|
||||||
- Make sure your changes are formatted correctly and consistently with the rest of the documentation
|
|
||||||
- Re-read what you wrote, and run a spellchecker on it to make sure you didn't miss anything
|
|
||||||
- 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
|
|
||||||
|
|
||||||
**Once you've filed the pull request:**
|
|
||||||
|
|
||||||
- Maintainers will review your pull request
|
|
||||||
- If a maintainer requests changes, first of all, try to think about this request critically and only after that implement and request another review
|
|
||||||
- If your PR gets accepted, it will soon be merged into the main branch. But your contribution will take effect only after the release of a new version of the action
|
|
||||||
> Sometimes maintainers reject pull requests and that's ok! Usually, along with rejection, we supply the reason for it. Nonetheless, we still really appreciate you taking the time to do it, and we don't take that lightly :heart:
|
|
||||||
|
|
||||||
## Contribute code
|
|
||||||
|
|
||||||
We like code commits a lot! They're super handy, and they keep the project going and doing the work it needs to do to be useful to others.
|
|
||||||
|
|
||||||
Code contributions of just about any size are acceptable!
|
|
||||||
|
|
||||||
The main difference between code contributions and documentation contributions is that contributing code requires the inclusion of relevant tests for the code being added or changed. Contributions without accompanying tests will be held off until a test is added unless the maintainers consider the specific tests to be either impossible or way too much of a burden for such a contribution.
|
|
||||||
|
|
||||||
**How to contribute:**
|
|
||||||
|
|
||||||
Pull requests are the easiest way to contribute changes to git repos at GitHub. They are the preferred contribution method, as they offer a nice way of commenting and amending the proposed 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
|
|
||||||
- **Run `pre-checkin` script to format, lint, build and test changes**
|
|
||||||
- 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 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
|
|
||||||
|
|
||||||
**Learn more about how to work with the repository:**
|
|
||||||
|
|
||||||
- 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 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
|
|
||||||
- You can also start formatting, building code, and testing with a single `pre-checkin` command
|
|
||||||
|
|
||||||
**Learn more about how to implement tests:**
|
|
||||||
|
|
||||||
Adding or changing tests is an integral part of making a change to the code.
|
|
||||||
Unit tests are in the `__tests__` folder, and end-to-end tests are in the `workflows` folder (in particular, in the file [versions.yml](https://github.com/actions/setup-go/blob/main/.github/workflows/versions.yml)).
|
|
||||||
|
|
||||||
- The contributor can add various types of tests (like unit tests or end-to-end tests), which, in his opinion, will be necessary and sufficient for testing new or changed functionality
|
|
||||||
- Tests should cover a successful execution, as well as some edge cases and possible errors
|
|
||||||
- As already mentioned, pull requests without tests will be considered more carefully by maintainers. If you are sure that in this situation the tests are not needed or cannot be implemented with a commensurate effort - please add this clarification message to your pull request
|
|
||||||
|
|
||||||
**Once you've filed the pull request:**
|
|
||||||
|
|
||||||
- CI will start automatically with some checks. Wait until the end of the execution and make sure that all checks passed successfully. If some checks fail, you can open them one by one, try to find the reason for failing and make changes to your code to resolve the problem
|
|
||||||
- Maintainers will review your pull request
|
|
||||||
- If a maintainer requests changes, first of all, try to think about his request critically and only after that implement and request another review
|
|
||||||
- If your PR gets accepted, it will soon be merged into the main branch. But your contribution will take effect only after the release of a new version of the action
|
|
||||||
> Sometimes maintainers reject pull requests and that's ok! Usually, along with rejection, we supply the reason for it. Nonetheless, we still really appreciate you taking the time to do it, and we don't take that lightly :heart:
|
|
||||||
|
|
||||||
## Provide support on issues
|
|
||||||
|
|
||||||
Helping out other users with their questions is an awesome way of contributing to any community. It's not uncommon for most of the issues on open source projects to be support-related questions by users trying to understand something they ran into or find their way around a known bug.
|
|
||||||
|
|
||||||
**To help other folks out with their questions:**
|
|
||||||
|
|
||||||
- Go to the [issue tracker](https://github.com/actions/setup-go/issues)
|
|
||||||
- Read through the list until you find something that you're familiar enough with to answer to
|
|
||||||
- Respond to the issue with whatever details are needed to clarify the question, or get more details about what's going on
|
|
||||||
- Once the discussion wraps up and things are clarified, ask the original issue filer (or a maintainer) to close it for you
|
|
||||||
|
|
||||||
*Some notes on picking up support issues:*
|
|
||||||
|
|
||||||
- Avoid responding to issues you don't know you can answer accurately
|
|
||||||
- Try to refer to past issues with accepted answers as much as possible. Link to them from your replies
|
|
||||||
- Be kind and patient with users. Often, folks who have run into confusing things might be upset or impatient. This is natural. If you feel uncomfortable in conversation with them, it's better to stay away or withdraw from the issue.
|
|
||||||
|
|
||||||
> If some user is violating our code of conduct [standards](https://github.com/actions/setup-go/blob/main/CODE_OF_CONDUCT.md#our-standards), refer to the [Enforcement](https://github.com/actions/setup-go/blob/main/CODE_OF_CONDUCT.md#enforcement) section of the Code of Conduct to resolve the conflict
|
|
||||||
|
|
||||||
|
|
||||||
## Review pull requests
|
|
||||||
|
|
||||||
|
|
||||||
Another great way to contribute is pull request reviews. Please, be extra kind: people who submit code/doc contributions are putting themselves in a pretty vulnerable position, and have put time and care into what they've done (even if that's not obvious to you!) Please, always respond with respect, and be understanding, but don't feel like you need to sacrifice your standards for their sake, either.
|
|
||||||
|
|
||||||
**How to review:**
|
|
||||||
|
|
||||||
- Go to the [pull requests](https://github.com/actions/setup-go/pulls)
|
|
||||||
- Make sure you're familiar with the code or documentation is updated, unless it's a minor change (spellchecking, minor formatting, etc.)
|
|
||||||
- Review changes using the GitHub functionality. You can ask a clarifying question, point out an error or suggest an alternative.
|
|
||||||
> Note: You may ask for minor changes - "nitpicks", but consider whether they are real blockers to merging or not
|
|
||||||
- Submit your review, which may include comments, an approval, or a changes request
|
|
9520
package-lock.json
generated
9520
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@ -1,17 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-go",
|
"name": "setup-go",
|
||||||
"version": "5.0.0",
|
"version": "1.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "setup go action",
|
"description": "setup go action",
|
||||||
"main": "lib/setup-go.js",
|
"main": "lib/setup-go.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc && ncc build -o dist/setup src/setup-go.ts && ncc build -o dist/cache-save src/cache-save.ts",
|
"build": "tsc && ncc build",
|
||||||
"format": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --write \"**/*.{ts,yml,yaml}\"",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --no-error-on-unmatched-pattern --config ./.prettierrc.js --check \"**/*.{ts,yml,yaml}\"",
|
"format-check": "prettier --check **/*.ts",
|
||||||
"lint": "eslint --config ./.eslintrc.js \"**/*.ts\"",
|
|
||||||
"lint:fix": "eslint --config ./.eslintrc.js \"**/*.ts\" --fix",
|
|
||||||
"test": "jest --coverage",
|
"test": "jest --coverage",
|
||||||
"pre-checkin": "npm run format && npm run lint:fix && npm run build && npm test"
|
"pre-checkin": "npm run format && npm run build && npm test"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,31 +23,22 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/cache": "^3.2.4",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/http-client": "^1.0.6",
|
||||||
"@actions/exec": "^1.1.0",
|
|
||||||
"@actions/glob": "^0.4.0",
|
|
||||||
"@actions/http-client": "^2.2.1",
|
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^1.5.5",
|
||||||
"semver": "^7.6.0"
|
"semver": "^6.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^29.5.12",
|
"@types/jest": "^27.0.2",
|
||||||
"@types/node": "^20.11.28",
|
"@types/node": "^12.0.4",
|
||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^6.0.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
"@zeit/ncc": "^0.21.0",
|
||||||
"@typescript-eslint/parser": "^5.54.0",
|
"jest": "^27.2.5",
|
||||||
"@vercel/ncc": "^0.38.1",
|
"jest-circus": "^27.2.5",
|
||||||
"eslint": "^8.57.0",
|
|
||||||
"eslint-config-prettier": "^8.6.0",
|
|
||||||
"eslint-plugin-jest": "^27.9.0",
|
|
||||||
"eslint-plugin-node": "^11.1.0",
|
|
||||||
"jest": "^29.7.0",
|
|
||||||
"jest-circus": "^29.7.0",
|
|
||||||
"nock": "^10.0.6",
|
"nock": "^10.0.6",
|
||||||
"prettier": "^2.8.4",
|
"prettier": "^1.17.1",
|
||||||
"ts-jest": "^29.1.2",
|
"ts-jest": "^27.0.5",
|
||||||
"typescript": "^5.4.2"
|
"typescript": "^3.8.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
import * as cache from '@actions/cache';
|
|
||||||
import * as core from '@actions/core';
|
|
||||||
import * as glob from '@actions/glob';
|
|
||||||
import path from 'path';
|
|
||||||
import fs from 'fs';
|
|
||||||
|
|
||||||
import {State, Outputs} from './constants';
|
|
||||||
import {PackageManagerInfo} from './package-managers';
|
|
||||||
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
|
|
||||||
|
|
||||||
export const restoreCache = async (
|
|
||||||
versionSpec: string,
|
|
||||||
packageManager: string,
|
|
||||||
cacheDependencyPath?: string
|
|
||||||
) => {
|
|
||||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
|
||||||
const platform = process.env.RUNNER_OS;
|
|
||||||
|
|
||||||
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
|
|
||||||
|
|
||||||
const dependencyFilePath = cacheDependencyPath
|
|
||||||
? cacheDependencyPath
|
|
||||||
: findDependencyFile(packageManagerInfo);
|
|
||||||
const fileHash = await glob.hashFiles(dependencyFilePath);
|
|
||||||
|
|
||||||
if (!fileHash) {
|
|
||||||
throw new Error(
|
|
||||||
'Some specified paths were not resolved, unable to cache dependencies.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const linuxVersion =
|
|
||||||
process.env.RUNNER_OS === 'Linux' ? `${process.env.ImageOS}-` : '';
|
|
||||||
const primaryKey = `setup-go-${platform}-${linuxVersion}go-${versionSpec}-${fileHash}`;
|
|
||||||
core.debug(`primary key is ${primaryKey}`);
|
|
||||||
|
|
||||||
core.saveState(State.CachePrimaryKey, primaryKey);
|
|
||||||
|
|
||||||
const cacheKey = await cache.restoreCache(cachePaths, primaryKey);
|
|
||||||
core.setOutput(Outputs.CacheHit, Boolean(cacheKey));
|
|
||||||
|
|
||||||
if (!cacheKey) {
|
|
||||||
core.info(`Cache is not found`);
|
|
||||||
core.setOutput(Outputs.CacheHit, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
core.saveState(State.CacheMatchedKey, cacheKey);
|
|
||||||
core.info(`Cache restored from key: ${cacheKey}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const findDependencyFile = (packageManager: PackageManagerInfo) => {
|
|
||||||
const dependencyFile = packageManager.dependencyFilePattern;
|
|
||||||
const workspace = process.env.GITHUB_WORKSPACE!;
|
|
||||||
const rootContent = fs.readdirSync(workspace);
|
|
||||||
|
|
||||||
const goSumFileExists = rootContent.includes(dependencyFile);
|
|
||||||
if (!goSumFileExists) {
|
|
||||||
throw new Error(
|
|
||||||
`Dependencies file is not found in ${workspace}. Supported file pattern: ${dependencyFile}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return path.join(workspace, dependencyFile);
|
|
||||||
};
|
|
@ -1,93 +0,0 @@
|
|||||||
import * as core from '@actions/core';
|
|
||||||
import * as cache from '@actions/cache';
|
|
||||||
import fs from 'fs';
|
|
||||||
import {State} from './constants';
|
|
||||||
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
|
|
||||||
|
|
||||||
// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
|
|
||||||
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
|
|
||||||
// throw an uncaught exception. Instead of failing this action, just warn.
|
|
||||||
process.on('uncaughtException', e => {
|
|
||||||
const warningPrefix = '[warning]';
|
|
||||||
core.info(`${warningPrefix}${e.message}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Added early exit to resolve issue with slow post action step:
|
|
||||||
// - https://github.com/actions/setup-node/issues/878
|
|
||||||
// https://github.com/actions/cache/pull/1217
|
|
||||||
export async function run(earlyExit?: boolean) {
|
|
||||||
try {
|
|
||||||
const cacheInput = core.getBooleanInput('cache');
|
|
||||||
if (cacheInput) {
|
|
||||||
await cachePackages();
|
|
||||||
|
|
||||||
if (earlyExit) {
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
let message = 'Unknown error!';
|
|
||||||
if (error instanceof Error) {
|
|
||||||
message = error.message;
|
|
||||||
}
|
|
||||||
if (typeof error === 'string') {
|
|
||||||
message = error;
|
|
||||||
}
|
|
||||||
core.warning(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const cachePackages = async () => {
|
|
||||||
const packageManager = 'default';
|
|
||||||
|
|
||||||
const state = core.getState(State.CacheMatchedKey);
|
|
||||||
const primaryKey = core.getState(State.CachePrimaryKey);
|
|
||||||
|
|
||||||
const packageManagerInfo = await getPackageManagerInfo(packageManager);
|
|
||||||
|
|
||||||
const cachePaths = await getCacheDirectoryPath(packageManagerInfo);
|
|
||||||
|
|
||||||
const nonExistingPaths = cachePaths.filter(
|
|
||||||
cachePath => !fs.existsSync(cachePath)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (nonExistingPaths.length === cachePaths.length) {
|
|
||||||
core.warning('There are no cache folders on the disk');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nonExistingPaths.length) {
|
|
||||||
logWarning(
|
|
||||||
`Cache folder path is retrieved but doesn't exist on disk: ${nonExistingPaths.join(
|
|
||||||
', '
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!primaryKey) {
|
|
||||||
core.info(
|
|
||||||
'Primary key was not generated. Please check the log messages above for more errors or information'
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (primaryKey === state) {
|
|
||||||
core.info(
|
|
||||||
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cacheId = await cache.saveCache(cachePaths, primaryKey);
|
|
||||||
if (cacheId === -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
core.info(`Cache saved with the key: ${primaryKey}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
function logWarning(message: string): void {
|
|
||||||
const warningPrefix = '[warning]';
|
|
||||||
core.info(`${warningPrefix}${message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
run(true);
|
|
@ -1,85 +0,0 @@
|
|||||||
import * as cache from '@actions/cache';
|
|
||||||
import * as core from '@actions/core';
|
|
||||||
import * as exec from '@actions/exec';
|
|
||||||
import {supportedPackageManagers, PackageManagerInfo} from './package-managers';
|
|
||||||
|
|
||||||
export const getCommandOutput = async (toolCommand: string) => {
|
|
||||||
let {stdout, stderr, exitCode} = await exec.getExecOutput(
|
|
||||||
toolCommand,
|
|
||||||
undefined,
|
|
||||||
{ignoreReturnCode: true}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (exitCode) {
|
|
||||||
stderr = !stderr.trim()
|
|
||||||
? `The '${toolCommand}' command failed with exit code: ${exitCode}`
|
|
||||||
: stderr;
|
|
||||||
throw new Error(stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stdout.trim();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getPackageManagerInfo = async (packageManager: string) => {
|
|
||||||
if (!supportedPackageManagers[packageManager]) {
|
|
||||||
throw new Error(
|
|
||||||
`It's not possible to use ${packageManager}, please, check correctness of the package manager name spelling.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const obtainedPackageManager = supportedPackageManagers[packageManager];
|
|
||||||
|
|
||||||
return obtainedPackageManager;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getCacheDirectoryPath = async (
|
|
||||||
packageManagerInfo: PackageManagerInfo
|
|
||||||
) => {
|
|
||||||
const pathOutputs = await Promise.allSettled(
|
|
||||||
packageManagerInfo.cacheFolderCommandList.map(async command =>
|
|
||||||
getCommandOutput(command)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const results = pathOutputs.map(item => {
|
|
||||||
if (item.status === 'fulfilled') {
|
|
||||||
return item.value;
|
|
||||||
} else {
|
|
||||||
core.info(`[warning]getting cache directory path failed: ${item.reason}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
});
|
|
||||||
|
|
||||||
const cachePaths = results.filter(item => item);
|
|
||||||
|
|
||||||
if (!cachePaths.length) {
|
|
||||||
throw new Error(`Could not get cache folder paths.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cachePaths;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function isGhes(): boolean {
|
|
||||||
const ghUrl = new URL(
|
|
||||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
|
||||||
);
|
|
||||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isCacheFeatureAvailable(): boolean {
|
|
||||||
if (cache.isFeatureAvailable()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isGhes()) {
|
|
||||||
core.warning(
|
|
||||||
'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.'
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
core.warning(
|
|
||||||
'The runner was not able to contact the cache service. Caching will be skipped'
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
export enum State {
|
|
||||||
CachePrimaryKey = 'CACHE_KEY',
|
|
||||||
CacheMatchedKey = 'CACHE_RESULT'
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum Outputs {
|
|
||||||
CacheHit = 'cache-hit'
|
|
||||||
}
|
|
349
src/installer.ts
349
src/installer.ts
@ -4,9 +4,7 @@ import * as path from 'path';
|
|||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as httpm from '@actions/http-client';
|
import * as httpm from '@actions/http-client';
|
||||||
import * as sys from './system';
|
import * as sys from './system';
|
||||||
import fs from 'fs';
|
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import {StableReleaseAlias} from './utils';
|
|
||||||
|
|
||||||
type InstallationType = 'dist' | 'manifest';
|
type InstallationType = 'dist' | 'manifest';
|
||||||
|
|
||||||
@ -32,58 +30,15 @@ export interface IGoVersionInfo {
|
|||||||
|
|
||||||
export async function getGo(
|
export async function getGo(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
checkLatest: boolean,
|
stable: boolean,
|
||||||
auth: string | undefined,
|
auth: string | undefined
|
||||||
arch = os.arch()
|
|
||||||
) {
|
) {
|
||||||
let manifest: tc.IToolRelease[] | undefined;
|
let osPlat: string = os.platform();
|
||||||
const osPlat: string = os.platform();
|
let osArch: string = os.arch();
|
||||||
|
|
||||||
if (
|
|
||||||
versionSpec === StableReleaseAlias.Stable ||
|
|
||||||
versionSpec === StableReleaseAlias.OldStable
|
|
||||||
) {
|
|
||||||
manifest = await getManifest(auth);
|
|
||||||
let stableVersion = await resolveStableVersionInput(
|
|
||||||
versionSpec,
|
|
||||||
arch,
|
|
||||||
osPlat,
|
|
||||||
manifest
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!stableVersion) {
|
|
||||||
stableVersion = await resolveStableVersionDist(versionSpec, arch);
|
|
||||||
if (!stableVersion) {
|
|
||||||
throw new Error(
|
|
||||||
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
core.info(`${versionSpec} version resolved as ${stableVersion}`);
|
|
||||||
|
|
||||||
versionSpec = stableVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (checkLatest) {
|
|
||||||
core.info('Attempting to resolve the latest version from the manifest...');
|
|
||||||
const resolvedVersion = await resolveVersionFromManifest(
|
|
||||||
versionSpec,
|
|
||||||
true,
|
|
||||||
auth,
|
|
||||||
arch,
|
|
||||||
manifest
|
|
||||||
);
|
|
||||||
if (resolvedVersion) {
|
|
||||||
versionSpec = resolvedVersion;
|
|
||||||
core.info(`Resolved as '${versionSpec}'`);
|
|
||||||
} else {
|
|
||||||
core.info(`Failed to resolve version ${versionSpec} from manifest`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check cache
|
// check cache
|
||||||
const toolPath = tc.find('go', versionSpec, arch);
|
let toolPath: string;
|
||||||
|
toolPath = tc.find('go', versionSpec);
|
||||||
// If not found in cache, download
|
// If not found in cache, download
|
||||||
if (toolPath) {
|
if (toolPath) {
|
||||||
core.info(`Found in cache @ ${toolPath}`);
|
core.info(`Found in cache @ ${toolPath}`);
|
||||||
@ -97,9 +52,9 @@ export async function getGo(
|
|||||||
// Try download from internal distribution (popular versions only)
|
// Try download from internal distribution (popular versions only)
|
||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
info = await getInfoFromManifest(versionSpec, true, auth, arch, manifest);
|
info = await getInfoFromManifest(versionSpec, stable, auth);
|
||||||
if (info) {
|
if (info) {
|
||||||
downloadPath = await installGoVersion(info, auth, arch);
|
downloadPath = await installGoVersion(info, auth);
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
core.info(
|
||||||
'Not found in manifest. Falling back to download directly from Go'
|
'Not found in manifest. Falling back to download directly from Go'
|
||||||
@ -114,9 +69,9 @@ export async function getGo(
|
|||||||
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
|
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
core.info((err as Error).message);
|
core.info(err.message);
|
||||||
}
|
}
|
||||||
core.debug((err as Error).stack ?? '');
|
core.debug(err.stack);
|
||||||
core.info('Falling back to download directly from Go');
|
core.info('Falling back to download directly from Go');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,16 +79,16 @@ export async function getGo(
|
|||||||
// Download from storage.googleapis.com
|
// Download from storage.googleapis.com
|
||||||
//
|
//
|
||||||
if (!downloadPath) {
|
if (!downloadPath) {
|
||||||
info = await getInfoFromDist(versionSpec, arch);
|
info = await getInfoFromDist(versionSpec, stable);
|
||||||
if (!info) {
|
if (!info) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${arch}.`
|
`Unable to find Go version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
core.info('Install from dist');
|
core.info('Install from dist');
|
||||||
downloadPath = await installGoVersion(info, undefined, arch);
|
downloadPath = await installGoVersion(info, undefined);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
|
throw new Error(`Failed to download version ${versionSpec}: ${err}`);
|
||||||
}
|
}
|
||||||
@ -142,110 +97,12 @@ export async function getGo(
|
|||||||
return downloadPath;
|
return downloadPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function resolveVersionFromManifest(
|
|
||||||
versionSpec: string,
|
|
||||||
stable: boolean,
|
|
||||||
auth: string | undefined,
|
|
||||||
arch: string,
|
|
||||||
manifest: tc.IToolRelease[] | undefined
|
|
||||||
): Promise<string | undefined> {
|
|
||||||
try {
|
|
||||||
const info = await getInfoFromManifest(
|
|
||||||
versionSpec,
|
|
||||||
stable,
|
|
||||||
auth,
|
|
||||||
arch,
|
|
||||||
manifest
|
|
||||||
);
|
|
||||||
return info?.resolvedVersion;
|
|
||||||
} catch (err) {
|
|
||||||
core.info('Unable to resolve a version from the manifest...');
|
|
||||||
core.debug((err as Error).message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// for github hosted windows runner handle latency of OS drive
|
|
||||||
// by avoiding write operations to C:
|
|
||||||
async function cacheWindowsDir(
|
|
||||||
extPath: string,
|
|
||||||
tool: string,
|
|
||||||
version: string,
|
|
||||||
arch: string
|
|
||||||
): Promise<string | false> {
|
|
||||||
if (os.platform() !== 'win32') return false;
|
|
||||||
|
|
||||||
// make sure the action runs in the hosted environment
|
|
||||||
if (
|
|
||||||
process.env['RUNNER_ENVIRONMENT'] !== 'github-hosted' &&
|
|
||||||
process.env['AGENT_ISSELFHOSTED'] === '1'
|
|
||||||
)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const defaultToolCacheRoot = process.env['RUNNER_TOOL_CACHE'];
|
|
||||||
if (!defaultToolCacheRoot) return false;
|
|
||||||
|
|
||||||
if (!fs.existsSync('d:\\') || !fs.existsSync('c:\\')) return false;
|
|
||||||
|
|
||||||
const actualToolCacheRoot = defaultToolCacheRoot
|
|
||||||
.replace('C:', 'D:')
|
|
||||||
.replace('c:', 'd:');
|
|
||||||
// make toolcache root to be on drive d:
|
|
||||||
process.env['RUNNER_TOOL_CACHE'] = actualToolCacheRoot;
|
|
||||||
|
|
||||||
const actualToolCacheDir = await tc.cacheDir(extPath, tool, version, arch);
|
|
||||||
|
|
||||||
// create a link from c: to d:
|
|
||||||
const defaultToolCacheDir = actualToolCacheDir.replace(
|
|
||||||
actualToolCacheRoot,
|
|
||||||
defaultToolCacheRoot
|
|
||||||
);
|
|
||||||
fs.mkdirSync(path.dirname(defaultToolCacheDir), {recursive: true});
|
|
||||||
fs.symlinkSync(actualToolCacheDir, defaultToolCacheDir, 'junction');
|
|
||||||
core.info(`Created link ${defaultToolCacheDir} => ${actualToolCacheDir}`);
|
|
||||||
|
|
||||||
const actualToolCacheCompleteFile = `${actualToolCacheDir}.complete`;
|
|
||||||
const defaultToolCacheCompleteFile = `${defaultToolCacheDir}.complete`;
|
|
||||||
fs.symlinkSync(
|
|
||||||
actualToolCacheCompleteFile,
|
|
||||||
defaultToolCacheCompleteFile,
|
|
||||||
'file'
|
|
||||||
);
|
|
||||||
core.info(
|
|
||||||
`Created link ${defaultToolCacheCompleteFile} => ${actualToolCacheCompleteFile}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// make outer code to continue using toolcache as if it were installed on c:
|
|
||||||
// restore toolcache root to default drive c:
|
|
||||||
process.env['RUNNER_TOOL_CACHE'] = defaultToolCacheRoot;
|
|
||||||
return defaultToolCacheDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function addExecutablesToToolCache(
|
|
||||||
extPath: string,
|
|
||||||
info: IGoVersionInfo,
|
|
||||||
arch: string
|
|
||||||
): Promise<string> {
|
|
||||||
const tool = 'go';
|
|
||||||
const version = makeSemver(info.resolvedVersion);
|
|
||||||
return (
|
|
||||||
(await cacheWindowsDir(extPath, tool, version, arch)) ||
|
|
||||||
(await tc.cacheDir(extPath, tool, version, arch))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function installGoVersion(
|
async function installGoVersion(
|
||||||
info: IGoVersionInfo,
|
info: IGoVersionInfo,
|
||||||
auth: string | undefined,
|
auth: string | undefined
|
||||||
arch: string
|
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
core.info(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
|
||||||
|
const downloadPath = await tc.downloadTool(info.downloadUrl, undefined, auth);
|
||||||
// Windows requires that we keep the extension (.zip) for extraction
|
|
||||||
const isWindows = os.platform() === 'win32';
|
|
||||||
const tempDir = process.env.RUNNER_TEMP || '.';
|
|
||||||
const fileName = isWindows ? path.join(tempDir, info.fileName) : undefined;
|
|
||||||
|
|
||||||
const downloadPath = await tc.downloadTool(info.downloadUrl, fileName, auth);
|
|
||||||
|
|
||||||
core.info('Extracting Go...');
|
core.info('Extracting Go...');
|
||||||
let extPath = await extractGoArchive(downloadPath);
|
let extPath = await extractGoArchive(downloadPath);
|
||||||
@ -255,10 +112,13 @@ async function installGoVersion(
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.info('Adding to the cache ...');
|
core.info('Adding to the cache ...');
|
||||||
const toolCacheDir = await addExecutablesToToolCache(extPath, info, arch);
|
const cachedDir = await tc.cacheDir(
|
||||||
core.info(`Successfully cached go to ${toolCacheDir}`);
|
extPath,
|
||||||
|
'go',
|
||||||
return toolCacheDir;
|
makeSemver(info.resolvedVersion)
|
||||||
|
);
|
||||||
|
core.info(`Successfully cached go to ${cachedDir}`);
|
||||||
|
return cachedDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function extractGoArchive(archivePath: string): Promise<string> {
|
export async function extractGoArchive(archivePath: string): Promise<string> {
|
||||||
@ -274,26 +134,20 @@ export async function extractGoArchive(archivePath: string): Promise<string> {
|
|||||||
return extPath;
|
return extPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getManifest(auth: string | undefined) {
|
|
||||||
return tc.getManifestFromRepo('actions', 'go-versions', auth, 'main');
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getInfoFromManifest(
|
export async function getInfoFromManifest(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
stable: boolean,
|
stable: boolean,
|
||||||
auth: string | undefined,
|
auth: string | undefined
|
||||||
arch = os.arch(),
|
|
||||||
manifest?: tc.IToolRelease[] | undefined
|
|
||||||
): Promise<IGoVersionInfo | null> {
|
): Promise<IGoVersionInfo | null> {
|
||||||
let info: IGoVersionInfo | null = null;
|
let info: IGoVersionInfo | null = null;
|
||||||
if (!manifest) {
|
const releases = await tc.getManifestFromRepo(
|
||||||
core.debug('No manifest cached');
|
'actions',
|
||||||
manifest = await getManifest(auth);
|
'go-versions',
|
||||||
}
|
auth,
|
||||||
|
'main'
|
||||||
|
);
|
||||||
core.info(`matching ${versionSpec}...`);
|
core.info(`matching ${versionSpec}...`);
|
||||||
|
const rel = await tc.findFromManifest(versionSpec, stable, releases);
|
||||||
const rel = await tc.findFromManifest(versionSpec, stable, manifest, arch);
|
|
||||||
|
|
||||||
if (rel && rel.files.length > 0) {
|
if (rel && rel.files.length > 0) {
|
||||||
info = <IGoVersionInfo>{};
|
info = <IGoVersionInfo>{};
|
||||||
@ -308,14 +162,15 @@ export async function getInfoFromManifest(
|
|||||||
|
|
||||||
async function getInfoFromDist(
|
async function getInfoFromDist(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
arch: string
|
stable: boolean
|
||||||
): Promise<IGoVersionInfo | null> {
|
): Promise<IGoVersionInfo | null> {
|
||||||
const version: IGoVersion | undefined = await findMatch(versionSpec, arch);
|
let version: IGoVersion | undefined;
|
||||||
|
version = await findMatch(versionSpec, stable);
|
||||||
if (!version) {
|
if (!version) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloadUrl = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
|
let downloadUrl: string = `https://storage.googleapis.com/golang/${version.files[0].filename}`;
|
||||||
|
|
||||||
return <IGoVersionInfo>{
|
return <IGoVersionInfo>{
|
||||||
type: 'dist',
|
type: 'dist',
|
||||||
@ -327,16 +182,16 @@ async function getInfoFromDist(
|
|||||||
|
|
||||||
export async function findMatch(
|
export async function findMatch(
|
||||||
versionSpec: string,
|
versionSpec: string,
|
||||||
arch = os.arch()
|
stable: boolean
|
||||||
): Promise<IGoVersion | undefined> {
|
): Promise<IGoVersion | undefined> {
|
||||||
const archFilter = sys.getArch(arch);
|
let archFilter = sys.getArch();
|
||||||
const platFilter = sys.getPlatform();
|
let platFilter = sys.getPlatform();
|
||||||
|
|
||||||
let result: IGoVersion | undefined;
|
let result: IGoVersion | undefined;
|
||||||
let match: IGoVersion | undefined;
|
let match: IGoVersion | undefined;
|
||||||
|
|
||||||
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
|
const dlUrl: string = 'https://golang.org/dl/?mode=json&include=all';
|
||||||
const candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
|
let candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
|
||||||
dlUrl
|
dlUrl
|
||||||
);
|
);
|
||||||
if (!candidates) {
|
if (!candidates) {
|
||||||
@ -345,11 +200,21 @@ export async function findMatch(
|
|||||||
|
|
||||||
let goFile: IGoVersionFile | undefined;
|
let goFile: IGoVersionFile | undefined;
|
||||||
for (let i = 0; i < candidates.length; i++) {
|
for (let i = 0; i < candidates.length; i++) {
|
||||||
const candidate: IGoVersion = candidates[i];
|
let candidate: IGoVersion = candidates[i];
|
||||||
const version = makeSemver(candidate.version);
|
let version = makeSemver(candidate.version);
|
||||||
|
|
||||||
|
// 1.13.0 is advertised as 1.13 preventing being able to match exactly 1.13.0
|
||||||
|
// since a semver of 1.13 would match latest 1.13
|
||||||
|
let parts: string[] = version.split('.');
|
||||||
|
if (parts.length == 2) {
|
||||||
|
version = version + '.0';
|
||||||
|
}
|
||||||
|
|
||||||
core.debug(`check ${version} satisfies ${versionSpec}`);
|
core.debug(`check ${version} satisfies ${versionSpec}`);
|
||||||
if (semver.satisfies(version, versionSpec)) {
|
if (
|
||||||
|
semver.satisfies(version, versionSpec) &&
|
||||||
|
(!stable || candidate.stable === stable)
|
||||||
|
) {
|
||||||
goFile = candidate.files.find(file => {
|
goFile = candidate.files.find(file => {
|
||||||
core.debug(
|
core.debug(
|
||||||
`${file.arch}===${archFilter} && ${file.os}===${platFilter}`
|
`${file.arch}===${archFilter} && ${file.os}===${platFilter}`
|
||||||
@ -378,7 +243,7 @@ export async function getVersionsDist(
|
|||||||
dlUrl: string
|
dlUrl: string
|
||||||
): Promise<IGoVersion[] | null> {
|
): Promise<IGoVersion[] | null> {
|
||||||
// this returns versions descending so latest is first
|
// this returns versions descending so latest is first
|
||||||
const http: httpm.HttpClient = new httpm.HttpClient('setup-go', [], {
|
let http: httpm.HttpClient = new httpm.HttpClient('setup-go', [], {
|
||||||
allowRedirects: true,
|
allowRedirects: true,
|
||||||
maxRedirects: 3
|
maxRedirects: 3
|
||||||
});
|
});
|
||||||
@ -389,106 +254,20 @@ export async function getVersionsDist(
|
|||||||
// Convert the go version syntax into semver for semver matching
|
// Convert the go version syntax into semver for semver matching
|
||||||
// 1.13.1 => 1.13.1
|
// 1.13.1 => 1.13.1
|
||||||
// 1.13 => 1.13.0
|
// 1.13 => 1.13.0
|
||||||
// 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
|
// 1.10beta1 => 1.10.0-beta1, 1.10rc1 => 1.10.0-rc1
|
||||||
// 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
|
// 1.8.5beta1 => 1.8.5-beta1, 1.8.5rc1 => 1.8.5-rc1
|
||||||
export function makeSemver(version: string): string {
|
export function makeSemver(version: string): string {
|
||||||
version = version.replace('go', '');
|
version = version.replace('go', '');
|
||||||
version = version.replace('beta', '-beta.').replace('rc', '-rc.');
|
version = version.replace('beta', '-beta').replace('rc', '-rc');
|
||||||
const parts = version.split('-');
|
let parts = version.split('-');
|
||||||
|
|
||||||
const semVersion = semver.coerce(parts[0])?.version;
|
let verPart: string = parts[0];
|
||||||
if (!semVersion) {
|
let prereleasePart = parts.length > 1 ? `-${parts[1]}` : '';
|
||||||
throw new Error(
|
|
||||||
`The version: ${version} can't be changed to SemVer notation`
|
let verParts: string[] = verPart.split('.');
|
||||||
);
|
if (verParts.length == 2) {
|
||||||
|
verPart += '.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parts[1]) {
|
return `${verPart}${prereleasePart}`;
|
||||||
return semVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fullVersion = semver.valid(`${semVersion}-${parts[1]}`);
|
|
||||||
|
|
||||||
if (!fullVersion) {
|
|
||||||
throw new Error(
|
|
||||||
`The version: ${version} can't be changed to SemVer notation`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return fullVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseGoVersionFile(versionFilePath: string): string {
|
|
||||||
const contents = fs.readFileSync(versionFilePath).toString();
|
|
||||||
|
|
||||||
if (
|
|
||||||
path.basename(versionFilePath) === 'go.mod' ||
|
|
||||||
path.basename(versionFilePath) === 'go.work'
|
|
||||||
) {
|
|
||||||
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
|
||||||
return match ? match[1] : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return contents.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function resolveStableVersionDist(versionSpec: string, arch: string) {
|
|
||||||
const archFilter = sys.getArch(arch);
|
|
||||||
const platFilter = sys.getPlatform();
|
|
||||||
const dlUrl = 'https://golang.org/dl/?mode=json&include=all';
|
|
||||||
const candidates: IGoVersion[] | null = await module.exports.getVersionsDist(
|
|
||||||
dlUrl
|
|
||||||
);
|
|
||||||
if (!candidates) {
|
|
||||||
throw new Error(`golang download url did not return results`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fixedCandidates = candidates.map(item => {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
version: makeSemver(item.version)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const stableVersion = await resolveStableVersionInput(
|
|
||||||
versionSpec,
|
|
||||||
archFilter,
|
|
||||||
platFilter,
|
|
||||||
fixedCandidates
|
|
||||||
);
|
|
||||||
|
|
||||||
return stableVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function resolveStableVersionInput(
|
|
||||||
versionSpec: string,
|
|
||||||
arch: string,
|
|
||||||
platform: string,
|
|
||||||
manifest: tc.IToolRelease[] | IGoVersion[]
|
|
||||||
) {
|
|
||||||
const releases = manifest
|
|
||||||
.map(item => {
|
|
||||||
const index = item.files.findIndex(
|
|
||||||
item => item.arch === arch && item.filename.includes(platform)
|
|
||||||
);
|
|
||||||
if (index === -1) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return item.version;
|
|
||||||
})
|
|
||||||
.filter(item => !!item && !semver.prerelease(item));
|
|
||||||
|
|
||||||
if (versionSpec === StableReleaseAlias.Stable) {
|
|
||||||
return releases[0];
|
|
||||||
} else {
|
|
||||||
const versions = releases.map(
|
|
||||||
release => `${semver.major(release)}.${semver.minor(release)}`
|
|
||||||
);
|
|
||||||
const uniqueVersions = Array.from(new Set(versions));
|
|
||||||
|
|
||||||
const oldstableVersion = releases.find(item =>
|
|
||||||
item.startsWith(uniqueVersions[1])
|
|
||||||
);
|
|
||||||
|
|
||||||
return oldstableVersion;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
130
src/main.ts
130
src/main.ts
@ -1,13 +1,10 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as io from '@actions/io';
|
import * as io from '@actions/io';
|
||||||
import * as installer from './installer';
|
import * as installer from './installer';
|
||||||
import * as semver from 'semver';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {restoreCache} from './cache-restore';
|
|
||||||
import {isCacheFeatureAvailable} from './cache-utils';
|
|
||||||
import cp from 'child_process';
|
import cp from 'child_process';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import os from 'os';
|
import {URL} from 'url';
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
try {
|
try {
|
||||||
@ -15,110 +12,70 @@ export async function run() {
|
|||||||
// versionSpec is optional. If supplied, install / use from the tool cache
|
// versionSpec is optional. If supplied, install / use from the tool cache
|
||||||
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
||||||
//
|
//
|
||||||
const versionSpec = resolveVersionInput();
|
let versionSpec = core.getInput('go-version');
|
||||||
|
|
||||||
const cache = core.getBooleanInput('cache');
|
// stable will be true unless false is the exact input
|
||||||
core.info(`Setup go version spec ${versionSpec}`);
|
// since getting unstable versions should be explicit
|
||||||
|
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
|
||||||
|
|
||||||
let arch = core.getInput('architecture');
|
core.info(`Setup go ${stable ? 'stable' : ''} version spec ${versionSpec}`);
|
||||||
|
|
||||||
if (!arch) {
|
|
||||||
arch = os.arch();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versionSpec) {
|
if (versionSpec) {
|
||||||
const token = core.getInput('token');
|
let token = core.getInput('token');
|
||||||
const auth = !token ? undefined : `token ${token}`;
|
let auth = !token || isGhes() ? undefined : `token ${token}`;
|
||||||
|
|
||||||
const checkLatest = core.getBooleanInput('check-latest');
|
const installDir = await installer.getGo(versionSpec, stable, auth);
|
||||||
|
|
||||||
const installDir = await installer.getGo(
|
|
||||||
versionSpec,
|
|
||||||
checkLatest,
|
|
||||||
auth,
|
|
||||||
arch
|
|
||||||
);
|
|
||||||
|
|
||||||
const installDirVersion = path.basename(path.dirname(installDir));
|
|
||||||
|
|
||||||
|
core.exportVariable('GOROOT', installDir);
|
||||||
core.addPath(path.join(installDir, 'bin'));
|
core.addPath(path.join(installDir, 'bin'));
|
||||||
core.info('Added go to the path');
|
core.info('Added go to the path');
|
||||||
|
|
||||||
const version = installer.makeSemver(installDirVersion);
|
let added = await addBinToPath();
|
||||||
// Go versions less than 1.9 require GOROOT to be set
|
core.debug(`add bin ${added}`);
|
||||||
if (semver.lt(version, '1.9.0')) {
|
core.info(`Successfully setup go version ${versionSpec}`);
|
||||||
core.info('Setting GOROOT for Go version < 1.9');
|
|
||||||
core.exportVariable('GOROOT', installDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
core.info(`Successfully set up Go version ${versionSpec}`);
|
|
||||||
} else {
|
|
||||||
core.info(
|
|
||||||
'[warning]go-version input was not specified. The action will try to use pre-installed version.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const added = await addBinToPath();
|
|
||||||
core.debug(`add bin ${added}`);
|
|
||||||
|
|
||||||
const goPath = await io.which('go');
|
|
||||||
const goVersion = (cp.execSync(`${goPath} version`) || '').toString();
|
|
||||||
|
|
||||||
if (cache && isCacheFeatureAvailable()) {
|
|
||||||
const packageManager = 'default';
|
|
||||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
|
||||||
try {
|
|
||||||
await restoreCache(
|
|
||||||
parseGoVersion(goVersion),
|
|
||||||
packageManager,
|
|
||||||
cacheDependencyPath
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
core.warning(`Restore cache failed: ${(error as Error).message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add problem matchers
|
// add problem matchers
|
||||||
const matchersPath = path.join(__dirname, '../..', 'matchers.json');
|
const matchersPath = path.join(__dirname, '..', 'matchers.json');
|
||||||
core.info(`##[add-matcher]${matchersPath}`);
|
core.info(`##[add-matcher]${matchersPath}`);
|
||||||
|
|
||||||
// output the version actually being used
|
// output the version actually being used
|
||||||
|
let goPath = await io.which('go');
|
||||||
|
let goVersion = (cp.execSync(`${goPath} version`) || '').toString();
|
||||||
core.info(goVersion);
|
core.info(goVersion);
|
||||||
|
|
||||||
core.setOutput('go-version', parseGoVersion(goVersion));
|
|
||||||
|
|
||||||
core.startGroup('go env');
|
core.startGroup('go env');
|
||||||
const goEnv = (cp.execSync(`${goPath} env`) || '').toString();
|
let goEnv = (cp.execSync(`${goPath} env`) || '').toString();
|
||||||
core.info(goEnv);
|
core.info(goEnv);
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed((error as Error).message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addBinToPath(): Promise<boolean> {
|
export async function addBinToPath(): Promise<boolean> {
|
||||||
let added = false;
|
let added = false;
|
||||||
const g = await io.which('go');
|
let g = await io.which('go');
|
||||||
core.debug(`which go :${g}:`);
|
core.debug(`which go :${g}:`);
|
||||||
if (!g) {
|
if (!g) {
|
||||||
core.debug('go not in the path');
|
core.debug('go not in the path');
|
||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buf = cp.execSync('go env GOPATH');
|
let buf = cp.execSync('go env GOPATH');
|
||||||
if (buf.length > 1) {
|
if (buf) {
|
||||||
const gp = buf.toString().trim();
|
let gp = buf.toString().trim();
|
||||||
core.debug(`go env GOPATH :${gp}:`);
|
core.debug(`go env GOPATH :${gp}:`);
|
||||||
if (!fs.existsSync(gp)) {
|
if (!fs.existsSync(gp)) {
|
||||||
// some of the hosted images have go install but not profile dir
|
// some of the hosted images have go install but not profile dir
|
||||||
core.debug(`creating ${gp}`);
|
core.debug(`creating ${gp}`);
|
||||||
await io.mkdirP(gp);
|
io.mkdirP(gp);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bp = path.join(gp, 'bin');
|
let bp = path.join(gp, 'bin');
|
||||||
if (!fs.existsSync(bp)) {
|
if (!fs.existsSync(bp)) {
|
||||||
core.debug(`creating ${bp}`);
|
core.debug(`creating ${bp}`);
|
||||||
await io.mkdirP(bp);
|
io.mkdirP(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.addPath(bp);
|
core.addPath(bp);
|
||||||
@ -127,36 +84,9 @@ export async function addBinToPath(): Promise<boolean> {
|
|||||||
return added;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parseGoVersion(versionString: string): string {
|
function isGhes(): boolean {
|
||||||
// get the installed version as an Action output
|
const ghUrl = new URL(
|
||||||
// based on go/src/cmd/go/internal/version/version.go:
|
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||||
// fmt.Printf("go version %s %s/%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
);
|
||||||
// expecting go<version> for runtime.Version()
|
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
|
||||||
return versionString.split(' ')[2].slice('go'.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveVersionInput(): string {
|
|
||||||
let version = core.getInput('go-version');
|
|
||||||
const versionFilePath = core.getInput('go-version-file');
|
|
||||||
|
|
||||||
if (version && versionFilePath) {
|
|
||||||
core.warning(
|
|
||||||
'Both go-version and go-version-file inputs are specified, only go-version will be used'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version) {
|
|
||||||
return version;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versionFilePath) {
|
|
||||||
if (!fs.existsSync(versionFilePath)) {
|
|
||||||
throw new Error(
|
|
||||||
`The specified go version file at: ${versionFilePath} does not exist`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
version = installer.parseGoVersionFile(versionFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return version;
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
type SupportedPackageManagers = {
|
|
||||||
[prop: string]: PackageManagerInfo;
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface PackageManagerInfo {
|
|
||||||
dependencyFilePattern: string;
|
|
||||||
cacheFolderCommandList: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export const supportedPackageManagers: SupportedPackageManagers = {
|
|
||||||
default: {
|
|
||||||
dependencyFilePattern: 'go.sum',
|
|
||||||
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,4 +1,4 @@
|
|||||||
import os from 'os';
|
let os = require('os');
|
||||||
|
|
||||||
export function getPlatform(): string {
|
export function getPlatform(): string {
|
||||||
// darwin and linux match already
|
// darwin and linux match already
|
||||||
@ -15,8 +15,9 @@ export function getPlatform(): string {
|
|||||||
return plat;
|
return plat;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getArch(arch: string): string {
|
export function getArch(): string {
|
||||||
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'.
|
// 'arm', 'arm64', 'ia32', 'mips', 'mipsel', 'ppc', 'ppc64', 's390', 's390x', 'x32', and 'x64'.
|
||||||
|
let arch: string = os.arch();
|
||||||
|
|
||||||
// wants amd64, 386, arm64, armv61, ppc641e, s390x
|
// wants amd64, 386, arm64, armv61, ppc641e, s390x
|
||||||
// currently not supported by runner but future proofed mapping
|
// currently not supported by runner but future proofed mapping
|
||||||
@ -30,9 +31,6 @@ export function getArch(arch: string): string {
|
|||||||
case 'x32':
|
case 'x32':
|
||||||
arch = '386';
|
arch = '386';
|
||||||
break;
|
break;
|
||||||
case 'arm':
|
|
||||||
arch = 'armv6l';
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return arch;
|
return arch;
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
export enum StableReleaseAlias {
|
|
||||||
Stable = 'stable',
|
|
||||||
OldStable = 'oldstable'
|
|
||||||
}
|
|
@ -4,6 +4,9 @@
|
|||||||
// "incremental": true, /* Enable incremental compilation */
|
// "incremental": true, /* Enable incremental compilation */
|
||||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||||
|
"lib": [
|
||||||
|
"es6"
|
||||||
|
],
|
||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
// "checkJs": true, /* Report errors in .js files. */
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||||
@ -45,9 +48,7 @@
|
|||||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||||
// "types": [], /* Type declaration files to be included in compilation. */
|
// "types": [], /* Type declaration files to be included in compilation. */
|
||||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
"resolveJsonModule": true, /* Allows importing modules with a '.json' extension, which is a common practice in node projects. */
|
|
||||||
"sourceMap": true,
|
|
||||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user