Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'actions:main' into main
  • Loading branch information
Ivan authored and GitHub committed Dec 14, 2022
2 parents de99728 + 6edd440 commit 339692a
Show file tree
Hide file tree
Showing 20 changed files with 2,717 additions and 1,473 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check-dist.yml
Expand Up @@ -27,6 +27,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: npm

- name: Install dependencies
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-new-action-version.yml
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Update the ${{ env.TAG_NAME }} tag
uses: actions/publish-action@v0.1.0
uses: actions/publish-action@v0.2.1
with:
source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
86 changes: 85 additions & 1 deletion .github/workflows/versions.yml
Expand Up @@ -12,14 +12,65 @@ on:
- cron: 0 0 * * *

jobs:
stable:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v3
- 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@v3
- 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@v3
- name: Setup Go ${{ matrix.version }} ${{ matrix.architecture }}
uses: ./
with:
go-version: ${{ matrix.version }}
architecture: ${{ matrix.architecture }}
- name: Verify Go
run: go version

local-cache:
name: Setup local-cache version
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
go: [1.12, 1.13, 1.14]
go: [1.17, 1.18, 1.19]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -66,6 +117,22 @@ jobs:
run: __tests__/verify-go.sh 1.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@v3
- name: Setup Go and check latest
uses: ./
with:
go-version-file: __tests__/data/go.work
- name: verify go
run: __tests__/verify-go.sh 1.19
shell: bash

setup-versions-from-manifest:
name: Setup ${{ matrix.go }} ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -107,3 +174,20 @@ jobs:
- name: verify go
run: __tests__/verify-go.sh ${{ matrix.go }}
shell: bash

architecture:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
go-version: [1.16, 1.17]
steps:
- uses: actions/checkout@v3
- name: Setup Go and check latest
uses: ./
with:
go-version: ${{ matrix.go-version }}
architecture: x64
- name: Verify Go
run: go version
2 changes: 1 addition & 1 deletion .licenses/npm/@actions/core.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 45 additions & 2 deletions README.md
Expand Up @@ -16,6 +16,7 @@ The V3 edition of the action offers:
- Proxy support
- Check latest version
- Caching packages dependencies
- stable and oldstable aliases
- 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 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).
Expand Down Expand Up @@ -95,6 +96,33 @@ steps:
check-latest: true
- run: go run hello.go
```

## Using stable/oldstable aliases

If `stable` is provided, action will get the latest stable version from the [`go-versions`](https://github.com/actions/go-versions/blob/main/versions-manifest.json) repository manifest.

If `oldstable` is provided, when current release is 1.19.x, action will resolve version as 1.18.x, where x is the latest patch release.

**Note:** using these aliases will result in same version as using corresponding minor release with `check-latest` input set to `true`

```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 'stable'
- run: go run hello.go
```

```yaml
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 'oldstable'
- run: go run hello.go
```

## Caching dependency files and build outputs:

The action has a built-in functionality for caching and restoring go modules and build outputs. It uses [actions/cache](https://github.com/actions/cache) under the hood but requires less configuration settings. The `cache` input is optional, and caching is turned off by default.
Expand Down Expand Up @@ -127,7 +155,7 @@ steps:
```
## Getting go version from the go.mod file

The `go-version-file` input accepts a path to a `go.mod` file containing the version of Go to be used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version sequentially in the runner's directory with the cached tools, in the [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers.
The `go-version-file` input accepts a path to a `go.mod` file or a `go.work` file that contains the version of Go to be used by a project. As the `go.mod` file contains only major and minor (e.g. 1.18) tags, the action will search for the latest available patch version sequentially in the runner's directory with the cached tools, in the [version-manifest.json](https://github.com/actions/go-versions/blob/main/versions-manifest.json) file or at the go servers.

If both the `go-version` and the `go-version-file` inputs are provided then the `go-version` input is used.
> The action will search for the `go.mod` file relative to the repository root
Expand Down Expand Up @@ -169,6 +197,21 @@ The `go-version` input supports the following syntax:

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@v3
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

The scripts and documentation in this project are released under the [MIT License](LICENSE)
Expand All @@ -179,4 +222,4 @@ Contributions are welcome! See [Contributor's Guide](docs/contributors.md)

## Code of Conduct

:wave: Be nice. See [our code of conduct](CONDUCT)
:wave: Be nice. See [our code of conduct](CODE_OF_CONDUCT.md)
19 changes: 16 additions & 3 deletions __tests__/cache-restore.test.ts
Expand Up @@ -17,6 +17,7 @@ describe('restoreCache', () => {
let infoSpy = jest.spyOn(core, 'info');
let setOutputSpy = jest.spyOn(core, 'setOutput');

const versionSpec = '1.13.1';
const packageManager = 'default';
const cacheDependencyPath = 'path';

Expand All @@ -40,7 +41,11 @@ describe('restoreCache', () => {

//Act + Assert
expect(async () => {
await cacheRestore.restoreCache(packageManager, cacheDependencyPath);
await cacheRestore.restoreCache(
versionSpec,
packageManager,
cacheDependencyPath
);
}).rejects.toThrowError(
'Some specified paths were not resolved, unable to cache dependencies.'
);
Expand All @@ -61,7 +66,11 @@ describe('restoreCache', () => {
});

//Act + Assert
await cacheRestore.restoreCache(packageManager, cacheDependencyPath);
await cacheRestore.restoreCache(
versionSpec,
packageManager,
cacheDependencyPath
);
expect(infoSpy).toBeCalledWith(`Cache is not found`);
});

Expand All @@ -80,7 +89,11 @@ describe('restoreCache', () => {
});

//Act + Assert
await cacheRestore.restoreCache(packageManager, cacheDependencyPath);
await cacheRestore.restoreCache(
versionSpec,
packageManager,
cacheDependencyPath
);
expect(setOutputSpy).toBeCalledWith('cache-hit', true);
});
});
3 changes: 3 additions & 0 deletions __tests__/data/go.work
@@ -0,0 +1,3 @@
go 1.19

use .

0 comments on commit 339692a

Please sign in to comment.