1
0
mirror of https://github.com/actions/setup-go.git synced 2026-02-02 05:37:21 +08:00

Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
2981b8ab90 Bump lodash from 4.17.21 to 4.17.23
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.21 to 4.17.23.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.21...4.17.23)

---
updated-dependencies:
- dependency-name: lodash
  dependency-version: 4.17.23
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-01-22 00:02:18 +00:00
9 changed files with 83 additions and 80 deletions

View File

@@ -24,18 +24,24 @@ steps:
### V6 Changes ### V6 Changes
**Node Runtime Upgrade** #### Node Runtime Upgrade
- **Upgraded from Node 20 to Node 24** - **Upgraded from Node 20 to Node 24**
- ⚠️ **Action Required**: Ensure your runner is on version v2.327.1 or later for compatibility - ⚠️ **Action Required**: Ensure your runner is on version v2.327.1 or later for compatibility
- See [Release Notes](https://github.com/actions/runner/releases/tag/v2.327.1) for more details - See [Release Notes](https://github.com/actions/runner/releases/tag/v2.327.1) for more details
**Enhanced Go Toolchain Management** #### Enhanced Go Toolchain Management
V6 introduces significant improvements for reliable and consistent Go version selection. Supports both `go` and `toolchain` directives in `go.mod`. If the `toolchain` directive is present, its version is used; otherwise, the action falls back to the go directive. V6 introduces significant improvements for reliable and consistent Go version selection:
**Cache Key Update** **Toolchain Directive Support**
Now correctly interprets both `go` and `toolchain` directives from `go.mod`:
```go
go 1.23.0 // Minimum required version
toolchain go1.23.2 // V6 uses this exact version
```
By default, caching for Go modules now relies on `go.mod`. To use `go.sum`, configure the `cache-dependency-path` input. **Intelligent Caching**
Cache keys now incorporate the `toolchain` directive version from `go.mod`, eliminating cache conflicts when switching between different toolchain versions within the same Go minor release.
For more details, see the [full release notes](https://github.com/actions/setup-go/releases/tag/v6.0.0). For more details, see the [full release notes](https://github.com/actions/setup-go/releases/tag/v6.0.0).
@@ -251,7 +257,7 @@ The action features integrated caching for Go modules and build outputs. Built o
#### Automatic Caching #### Automatic Caching
Default behavior: Searches for `go.mod` in the repository root and uses its hash for the cache key. Default behavior: Searches for `go.sum` in the repository root and uses its hash for the cache key.
```yaml ```yaml
steps: steps:
@@ -362,7 +368,7 @@ jobs:
path: | path: |
${{ env.GO_MOD_CACHE }} ${{ env.GO_MOD_CACHE }}
${{ env.GO_BUILD_CACHE }} ${{ env.GO_BUILD_CACHE }}
key: setup-go-${{ runner.os }}-${{ env.ARCH }}-${{ env.CACHE_OS_SUFFIX }}go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('**/go.mod') }} key: setup-go-${{ runner.os }}-${{ env.ARCH }}-${{ env.CACHE_OS_SUFFIX }}go-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('**/go.sum') }}
- name: Download modules - name: Download modules
run: go mod download run: go mod download
- name: Build - name: Build

View File

@@ -1,83 +1,94 @@
import * as cache from '@actions/cache'; import * as cache from '@actions/cache';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as glob from '@actions/glob'; import * as glob from '@actions/glob';
import fs from 'fs';
import * as cacheRestore from '../src/cache-restore'; import * as cacheRestore from '../src/cache-restore';
import * as cacheUtils from '../src/cache-utils'; import * as cacheUtils from '../src/cache-utils';
import {PackageManagerInfo} from '../src/package-managers'; import {PackageManagerInfo} from '../src/package-managers';
describe('restoreCache', () => { describe('restoreCache', () => {
let hashFilesSpy: jest.SpyInstance; //Arrange
let getCacheDirectoryPathSpy: jest.SpyInstance; const hashFilesSpy = jest.spyOn(glob, 'hashFiles');
let restoreCacheSpy: jest.SpyInstance; const getCacheDirectoryPathSpy = jest.spyOn(
let infoSpy: jest.SpyInstance; cacheUtils,
let setOutputSpy: jest.SpyInstance; '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 versionSpec = '1.13.1';
const packageManager = 'default'; const packageManager = 'default';
const cacheDependencyPath = 'path'; const cacheDependencyPath = 'path';
let originalWorkspace: string | undefined;
beforeEach(() => { beforeEach(() => {
originalWorkspace = process.env.GITHUB_WORKSPACE;
process.env.GITHUB_WORKSPACE = '/test/workspace';
//Arrange
hashFilesSpy = jest.spyOn(glob, 'hashFiles');
getCacheDirectoryPathSpy = jest.spyOn(cacheUtils, 'getCacheDirectoryPath');
restoreCacheSpy = jest.spyOn(cache, 'restoreCache');
infoSpy = jest.spyOn(core, 'info');
setOutputSpy = jest.spyOn(core, 'setOutput');
getCacheDirectoryPathSpy.mockImplementation( getCacheDirectoryPathSpy.mockImplementation(
(PackageManager: PackageManagerInfo) => { (PackageManager: PackageManagerInfo) => {
return Promise.resolve([ return new Promise<string[]>(resolve => {
'cache_directory_path', resolve(['cache_directory_path', 'cache_directory_path']);
'cache_directory_path' });
]);
} }
); );
}); });
afterEach(() => {
process.env.GITHUB_WORKSPACE = originalWorkspace;
jest.restoreAllMocks();
});
it('should throw if dependency file path is not valid', async () => { it('should throw if dependency file path is not valid', async () => {
// Arrange //Arrange
hashFilesSpy.mockImplementation(() => Promise.resolve('')); hashFilesSpy.mockImplementation((somePath: string) => {
// Act + Assert return new Promise<string>(resolve => {
await expect( resolve('');
cacheRestore.restoreCache( });
});
//Act + Assert
await expect(async () => {
await cacheRestore.restoreCache(
versionSpec, versionSpec,
packageManager, packageManager,
cacheDependencyPath cacheDependencyPath
) );
).rejects.toThrow( }).rejects.toThrow(
'Some specified paths were not resolved, unable to cache dependencies.' 'Some specified paths were not resolved, unable to cache dependencies.'
); );
}); });
it('should inform if cache hit is not occurred', async () => { it('should inform if cache hit is not occured', async () => {
// Arrange //Arrange
hashFilesSpy.mockImplementation(() => Promise.resolve('file_hash')); hashFilesSpy.mockImplementation((somePath: string) => {
restoreCacheSpy.mockImplementation(() => Promise.resolve('')); return new Promise<string>(resolve => {
// Act + Assert resolve('file_hash');
});
});
restoreCacheSpy.mockImplementation(() => {
return new Promise<string>(resolve => {
resolve('');
});
});
//Act + Assert
await cacheRestore.restoreCache( await cacheRestore.restoreCache(
versionSpec, versionSpec,
packageManager, packageManager,
cacheDependencyPath cacheDependencyPath
); );
expect(infoSpy).toHaveBeenCalledWith('Cache is not found'); expect(infoSpy).toHaveBeenCalledWith(`Cache is not found`);
}); });
it('should set output if cache hit is occurred', async () => { it('should set output if cache hit is occured', async () => {
// Arrange //Arrange
hashFilesSpy.mockImplementation(() => Promise.resolve('file_hash')); hashFilesSpy.mockImplementation((somePath: string) => {
restoreCacheSpy.mockImplementation(() => Promise.resolve('cache_key')); return new Promise<string>(resolve => {
// Act + Assert resolve('file_hash');
});
});
restoreCacheSpy.mockImplementation(() => {
return new Promise<string>(resolve => {
resolve('cache_key');
});
});
//Act + Assert
await cacheRestore.restoreCache( await cacheRestore.restoreCache(
versionSpec, versionSpec,
packageManager, packageManager,
@@ -85,18 +96,4 @@ describe('restoreCache', () => {
); );
expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true); expect(setOutputSpy).toHaveBeenCalledWith('cache-hit', true);
}); });
it('should throw if dependency file is not found in workspace', async () => {
jest.spyOn(fs, 'readdirSync').mockReturnValue(['main.go'] as any);
await expect(
cacheRestore.restoreCache(
versionSpec,
packageManager
// No cacheDependencyPath
)
).rejects.toThrow(
'Dependencies file is not found in /test/workspace. Supported file pattern: go.mod'
);
});
}); });

View File

@@ -47,7 +47,7 @@ describe('getPackageManagerInfo', () => {
//Arrange //Arrange
const packageManagerName = 'default'; const packageManagerName = 'default';
const expectedResult = { const expectedResult = {
dependencyFilePattern: 'go.mod', dependencyFilePattern: 'go.sum',
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE'] cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
}; };
@@ -73,7 +73,7 @@ describe('getCacheDirectoryPath', () => {
const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput'); const getExecOutputSpy = jest.spyOn(exec, 'getExecOutput');
const validPackageManager: PackageManagerInfo = { const validPackageManager: PackageManagerInfo = {
dependencyFilePattern: 'go.mod', dependencyFilePattern: 'go.sum',
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE'] cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
}; };

View File

@@ -16,7 +16,7 @@ inputs:
description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching. description: Used to specify whether caching is needed. Set to true, if you'd like to enable caching.
default: true default: true
cache-dependency-path: cache-dependency-path:
description: 'Used to specify the path to a dependency file (e.g., go.mod, go.sum)' description: 'Used to specify the path to a dependency file - go.sum'
architecture: architecture:
description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.' description: 'Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default.'
outputs: outputs:

View File

@@ -44277,7 +44277,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.supportedPackageManagers = void 0; exports.supportedPackageManagers = void 0;
exports.supportedPackageManagers = { exports.supportedPackageManagers = {
default: { default: {
dependencyFilePattern: 'go.mod', dependencyFilePattern: 'go.sum',
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE'] cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
} }
}; };

6
dist/setup/index.js vendored
View File

@@ -49364,8 +49364,8 @@ const findDependencyFile = (packageManager) => {
const dependencyFile = packageManager.dependencyFilePattern; const dependencyFile = packageManager.dependencyFilePattern;
const workspace = process.env.GITHUB_WORKSPACE; const workspace = process.env.GITHUB_WORKSPACE;
const rootContent = fs_1.default.readdirSync(workspace); const rootContent = fs_1.default.readdirSync(workspace);
const goModFileExists = rootContent.includes(dependencyFile); const goSumFileExists = rootContent.includes(dependencyFile);
if (!goModFileExists) { if (!goSumFileExists) {
throw new Error(`Dependencies file is not found in ${workspace}. Supported file pattern: ${dependencyFile}`); throw new Error(`Dependencies file is not found in ${workspace}. Supported file pattern: ${dependencyFile}`);
} }
return path_1.default.join(workspace, dependencyFile); return path_1.default.join(workspace, dependencyFile);
@@ -50182,7 +50182,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.supportedPackageManagers = void 0; exports.supportedPackageManagers = void 0;
exports.supportedPackageManagers = { exports.supportedPackageManagers = {
default: { default: {
dependencyFilePattern: 'go.mod', dependencyFilePattern: 'go.sum',
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE'] cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
} }
}; };

6
package-lock.json generated
View File

@@ -4840,9 +4840,9 @@
} }
}, },
"node_modules/lodash": { "node_modules/lodash": {
"version": "4.17.21", "version": "4.17.23",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.23.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "integrity": "sha512-LgVTMpQtIopCi79SJeDiP0TfWi5CNEc/L/aRdTh3yIvmZXTnheWpKjSZhnvMl8iXbC1tFg9gdHHDMLoV7CnG+w==",
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },

View File

@@ -55,8 +55,8 @@ const findDependencyFile = (packageManager: PackageManagerInfo) => {
const workspace = process.env.GITHUB_WORKSPACE!; const workspace = process.env.GITHUB_WORKSPACE!;
const rootContent = fs.readdirSync(workspace); const rootContent = fs.readdirSync(workspace);
const goModFileExists = rootContent.includes(dependencyFile); const goSumFileExists = rootContent.includes(dependencyFile);
if (!goModFileExists) { if (!goSumFileExists) {
throw new Error( throw new Error(
`Dependencies file is not found in ${workspace}. Supported file pattern: ${dependencyFile}` `Dependencies file is not found in ${workspace}. Supported file pattern: ${dependencyFile}`
); );

View File

@@ -9,7 +9,7 @@ export interface PackageManagerInfo {
export const supportedPackageManagers: SupportedPackageManagers = { export const supportedPackageManagers: SupportedPackageManagers = {
default: { default: {
dependencyFilePattern: 'go.mod', dependencyFilePattern: 'go.sum',
cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE'] cacheFolderCommandList: ['go env GOMODCACHE', 'go env GOCACHE']
} }
}; };