From 146dd77449a0efd02f75d5bc5e4c69c3583cea2b Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 26 Aug 2020 12:09:04 +0200 Subject: [PATCH 01/18] The path can be relative or absolute under $GITHUB_WORKSPACE * README.md: * action.yml: * adrs/0153-checkout-v2.md: --- README.md | 14 +++++++++++++- action.yml | 2 +- adrs/0153-checkout-v2.md | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9c56a6f..2143962 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous # Default: true persist-credentials: '' - # Relative path under $GITHUB_WORKSPACE to place the repository + # Relative or absolute path under $GITHUB_WORKSPACE to place the repository path: '' # Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching @@ -160,6 +160,18 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous path: my-tools ``` +## Checkout repo with a environment based path (side by side) + +```yaml +env: + main_path: ${{ github.workspace }}/main +steps: +- name: Checkout + uses: actions/checkout@v2 + with: + path: ${{ env.main_path }} +``` + ## Checkout multiple repos (nested) ```yaml diff --git a/action.yml b/action.yml index 91d3982..19ea55e 100644 --- a/action.yml +++ b/action.yml @@ -49,7 +49,7 @@ inputs: description: 'Whether to configure the token or SSH key with the local git config' default: true path: - description: 'Relative path under $GITHUB_WORKSPACE to place the repository' + description: 'Relative or absolute path under $GITHUB_WORKSPACE to place the repository' clean: description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching' default: true diff --git a/adrs/0153-checkout-v2.md b/adrs/0153-checkout-v2.md index 74730c7..ebe1f5f 100644 --- a/adrs/0153-checkout-v2.md +++ b/adrs/0153-checkout-v2.md @@ -65,7 +65,7 @@ We want to take this opportunity to make behavioral changes, from v1. This docum description: 'Whether to configure the token or SSH key with the local git config' default: true path: - description: 'Relative path under $GITHUB_WORKSPACE to place the repository' + description: 'Relative or absolute path under $GITHUB_WORKSPACE to place the repository' clean: description: 'Whether to execute `git clean -ffdx && git reset --hard HEAD` before fetching' default: true @@ -287,4 +287,4 @@ Note: - Update samples to consume `actions/checkout@v2` - Job containers now require git in the PATH for checkout, otherwise fallback to REST API - Minimum git version 2.18 -- Update problem matcher logic regarding source file verification (runner) \ No newline at end of file +- Update problem matcher logic regarding source file verification (runner) From e67ad3383bb9ed7870b02fae47b48ab0f5a151a1 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 26 Aug 2020 12:11:07 +0200 Subject: [PATCH 02/18] Removed side by side * README.md: --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2143962..dbcba78 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ Refer [here](https://github.com/actions/checkout/blob/v1/README.md) for previous path: my-tools ``` -## Checkout repo with a environment based path (side by side) +## Checkout repo with a environment based path ```yaml env: From 4f92610a9793e6a300af7cce7417ebbace7f009f Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 26 Aug 2020 12:18:55 +0200 Subject: [PATCH 03/18] Added environment based path test * __test__/verify-environment-path.sh: Added. * .github/workflows/test.yml: --- .github/workflows/test.yml | 12 ++++++++++++ __test__/verify-environment-path.sh | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100755 __test__/verify-environment-path.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 87360d3..813b9cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,6 +10,8 @@ on: jobs: build: runs-on: ubuntu-latest + env: + main_path: main_path_test steps: - uses: actions/setup-node@v1 with: @@ -57,6 +59,16 @@ jobs: shell: bash run: __test__/verify-clean.sh + # Use environment variable as path + - name: Environment path test + uses: ./ + with: + ref: test-data/v2/basic + path: ${{ env.main_path }} + - name: Verify environment path test + shell: bash + run: __test__/verify-environment-path.sh + # Side by side - name: Checkout side by side 1 uses: ./ diff --git a/__test__/verify-environment-path.sh b/__test__/verify-environment-path.sh new file mode 100755 index 0000000..bd64859 --- /dev/null +++ b/__test__/verify-environment-path.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +if [ ! -f "./main_path_test/basic-file.txt" ]; then + echo "Expected file does not exist" + exit 1 +fi From 388793bd972dbe0d202b25fde9d1b8fcd1d49f23 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 26 Aug 2020 12:25:15 +0200 Subject: [PATCH 04/18] Use ref as it should * .github/workflows/test.yml: --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 813b9cd..c1bfc66 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: - name: Environment path test uses: ./ with: - ref: test-data/v2/basic + ref: test-data/v2/environment-path path: ${{ env.main_path }} - name: Verify environment path test shell: bash From d345e1892f7361d6f92f372f5ae70c5ca506b0bc Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 26 Aug 2020 12:26:01 +0200 Subject: [PATCH 05/18] Back to basic * .github/workflows/test.yml: --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c1bfc66..813b9cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: - name: Environment path test uses: ./ with: - ref: test-data/v2/environment-path + ref: test-data/v2/basic path: ${{ env.main_path }} - name: Verify environment path test shell: bash From d795c2780e79f41b814bf5dc36f864c846931d96 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Wed, 26 Aug 2020 12:44:28 +0200 Subject: [PATCH 06/18] Move env to test step * .github/workflows/test.yml: --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 813b9cd..a3e6424 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,8 +10,6 @@ on: jobs: build: runs-on: ubuntu-latest - env: - main_path: main_path_test steps: - uses: actions/setup-node@v1 with: @@ -26,6 +24,8 @@ jobs: run: __test__/verify-no-unstaged-changes.sh test: + env: + main_path: main_path_test strategy: matrix: runs-on: [ubuntu-latest, macos-latest, windows-latest] From b6849436894e144dbce29d7d7fda2ae3bf9d8365 Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Thu, 5 Sep 2024 08:57:13 -0700 Subject: [PATCH 07/18] Add Ref and Commit outputs (#1180) Signed-off-by: Luca Comellini --- .github/workflows/test.yml | 34 ++++++++++++++++++++++++++++++++++ action.yml | 5 +++++ dist/index.js | 4 +++- src/git-source-provider.ts | 3 ++- src/main.ts | 1 + 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1ef3c31..cde9f06 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -295,3 +295,37 @@ jobs: uses: actions/checkout@v4.1.6 with: path: localClone + + test-output: + runs-on: ubuntu-latest + steps: + # Clone this repo + - name: Checkout + uses: actions/checkout@v4.1.6 + + # Basic checkout using git + - name: Checkout basic + id: checkout + uses: ./ + with: + ref: test-data/v2/basic + + # Verify output + - name: Verify output + run: | + echo "Commit: ${{ steps.checkout.outputs.commit }}" + echo "Ref: ${{ steps.checkout.outputs.ref }}" + + if [ "${{ steps.checkout.outputs.ref }}" != "test-data/v2/basic" ]; then + echo "Expected ref to be test-data/v2/basic" + exit 1 + fi + + if [ "${{ steps.checkout.outputs.commit }}" != "82f71901cf8c021332310dcc8cdba84c4193ff5d" ]; then + echo "Expected commit to be 82f71901cf8c021332310dcc8cdba84c4193ff5d" + exit 1 + fi + + # needed to make checkout post cleanup succeed + - name: Fix Checkout + uses: actions/checkout@v4.1.6 diff --git a/action.yml b/action.yml index 75d5ae2..6842eb8 100644 --- a/action.yml +++ b/action.yml @@ -98,6 +98,11 @@ inputs: github-server-url: description: The base URL for the GitHub instance that you are trying to clone from, will use environment defaults to fetch from the same instance that the workflow is running from unless specified. Example URLs are https://github.com or https://my-ghes-server.example.com required: false +outputs: + ref: + description: 'The branch, tag or SHA that was checked out' + commit: + description: 'The commit SHA that was checked out' runs: using: node20 main: dist/index.js diff --git a/dist/index.js b/dist/index.js index 9d959a9..ae427a4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1355,7 +1355,8 @@ function getSource(settings) { // Get commit information const commitInfo = yield git.log1(); // Log commit sha - yield git.log1("--format='%H'"); + const commitSHA = yield git.log1('--format=%H'); + core.setOutput('commit', commitSHA.trim()); // Check for incorrect pull request merge commit yield refHelper.checkCommitInfo(settings.authToken, commitInfo, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.githubServerUrl); } @@ -1897,6 +1898,7 @@ function run() { coreCommand.issueCommand('add-matcher', {}, path.join(__dirname, 'problem-matcher.json')); // Get sources yield gitSourceProvider.getSource(sourceSettings); + core.setOutput('ref', sourceSettings.ref); } finally { // Unregister problem matcher diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index f723d94..2d35138 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -261,7 +261,8 @@ export async function getSource(settings: IGitSourceSettings): Promise { const commitInfo = await git.log1() // Log commit sha - await git.log1("--format='%H'") + const commitSHA = await git.log1('--format=%H') + core.setOutput('commit', commitSHA.trim()) // Check for incorrect pull request merge commit await refHelper.checkCommitInfo( diff --git a/src/main.ts b/src/main.ts index 97a27af..0684c6f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,6 +19,7 @@ async function run(): Promise { // Get sources await gitSourceProvider.getSource(sourceSettings) + core.setOutput('ref', sourceSettings.ref) } finally { // Unregister problem matcher coreCommand.issueCommand('remove-matcher', {owner: 'checkout-git'}, '') From db0cee9a514becbbd4a101a5fbbbf47865ee316c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:04:17 -0400 Subject: [PATCH 08/18] Bump the minor-npm-dependencies group across 1 directory with 4 updates (#1872) * Bump the minor-npm-dependencies group across 1 directory with 4 updates Bumps the minor-npm-dependencies group with 4 updates in the / directory: [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest), [prettier](https://github.com/prettier/prettier), [ts-jest](https://github.com/kulshekhar/ts-jest) and [typescript](https://github.com/Microsoft/TypeScript). Updates `eslint-plugin-jest` from 28.5.0 to 28.8.2 - [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases) - [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v28.5.0...v28.8.2) Updates `prettier` from 3.2.5 to 3.3.3 - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/3.2.5...3.3.3) Updates `ts-jest` from 29.1.2 to 29.2.5 - [Release notes](https://github.com/kulshekhar/ts-jest/releases) - [Changelog](https://github.com/kulshekhar/ts-jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/kulshekhar/ts-jest/compare/v29.1.2...v29.2.5) Updates `typescript` from 5.4.5 to 5.5.4 - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml) - [Commits](https://github.com/Microsoft/TypeScript/compare/v5.4.5...v5.5.4) --- updated-dependencies: - dependency-name: eslint-plugin-jest dependency-type: direct:development update-type: version-update:semver-minor dependency-group: minor-npm-dependencies - dependency-name: prettier dependency-type: direct:development update-type: version-update:semver-minor dependency-group: minor-npm-dependencies - dependency-name: ts-jest dependency-type: direct:development update-type: version-update:semver-minor dependency-group: minor-npm-dependencies - dependency-name: typescript dependency-type: direct:development update-type: version-update:semver-minor dependency-group: minor-npm-dependencies ... Signed-off-by: dependabot[bot] * `npm run build` --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Josh Gross --- dist/index.js | 71 +++++++++----------- package-lock.json | 164 ++++++++++++++++++++++++++++++++-------------- package.json | 8 +-- 3 files changed, 150 insertions(+), 93 deletions(-) diff --git a/dist/index.js b/dist/index.js index ae427a4..2b7dd09 100644 --- a/dist/index.js +++ b/dist/index.js @@ -30,7 +30,9 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.fileExistsSync = exports.existsSync = exports.directoryExistsSync = void 0; +exports.directoryExistsSync = directoryExistsSync; +exports.existsSync = existsSync; +exports.fileExistsSync = fileExistsSync; const fs = __importStar(__nccwpck_require__(7147)); function directoryExistsSync(path, required) { var _a; @@ -58,7 +60,6 @@ function directoryExistsSync(path, required) { } throw new Error(`Directory '${path}' does not exist`); } -exports.directoryExistsSync = directoryExistsSync; function existsSync(path) { var _a; if (!path) { @@ -75,7 +76,6 @@ function existsSync(path) { } return true; } -exports.existsSync = existsSync; function fileExistsSync(path) { var _a; if (!path) { @@ -96,7 +96,6 @@ function fileExistsSync(path) { } return false; } -exports.fileExistsSync = fileExistsSync; /***/ }), @@ -139,7 +138,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.createAuthHelper = void 0; +exports.createAuthHelper = createAuthHelper; const assert = __importStar(__nccwpck_require__(9491)); const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); @@ -156,7 +155,6 @@ const SSH_COMMAND_KEY = 'core.sshCommand'; function createAuthHelper(git, settings) { return new GitAuthHelper(git, settings); } -exports.createAuthHelper = createAuthHelper; class GitAuthHelper { constructor(gitCommandManager, gitSourceSettings) { this.insteadOfValues = []; @@ -475,7 +473,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.createCommandManager = exports.MinimumGitSparseCheckoutVersion = exports.MinimumGitVersion = void 0; +exports.MinimumGitSparseCheckoutVersion = exports.MinimumGitVersion = void 0; +exports.createCommandManager = createCommandManager; const core = __importStar(__nccwpck_require__(2186)); const exec = __importStar(__nccwpck_require__(1514)); const fs = __importStar(__nccwpck_require__(7147)); @@ -496,7 +495,6 @@ function createCommandManager(workingDirectory, lfs, doSparseCheckout) { return yield GitCommandManager.createCommandManager(workingDirectory, lfs, doSparseCheckout); }); } -exports.createCommandManager = createCommandManager; class GitCommandManager { // Private constructor; use createCommandManager() constructor() { @@ -1020,7 +1018,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.prepareExistingDirectory = void 0; +exports.prepareExistingDirectory = prepareExistingDirectory; const assert = __importStar(__nccwpck_require__(9491)); const core = __importStar(__nccwpck_require__(2186)); const fs = __importStar(__nccwpck_require__(7147)); @@ -1124,7 +1122,6 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean, ref } }); } -exports.prepareExistingDirectory = prepareExistingDirectory; /***/ }), @@ -1167,7 +1164,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.cleanup = exports.getSource = void 0; +exports.getSource = getSource; +exports.cleanup = cleanup; const core = __importStar(__nccwpck_require__(2186)); const fsHelper = __importStar(__nccwpck_require__(7219)); const gitAuthHelper = __importStar(__nccwpck_require__(2565)); @@ -1373,7 +1371,6 @@ function getSource(settings) { } }); } -exports.getSource = getSource; function cleanup(repositoryPath) { return __awaiter(this, void 0, void 0, function* () { // Repo exists? @@ -1409,7 +1406,6 @@ function cleanup(repositoryPath) { } }); } -exports.cleanup = cleanup; function getGitCommandManager(settings) { return __awaiter(this, void 0, void 0, function* () { core.info(`Working directory is '${settings.repositoryPath}'`); @@ -1548,7 +1544,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getDefaultBranch = exports.downloadRepository = void 0; +exports.downloadRepository = downloadRepository; +exports.getDefaultBranch = getDefaultBranch; const assert = __importStar(__nccwpck_require__(9491)); const core = __importStar(__nccwpck_require__(2186)); const fs = __importStar(__nccwpck_require__(7147)); @@ -1612,7 +1609,6 @@ function downloadRepository(authToken, owner, repo, ref, commit, repositoryPath, yield io.rmRF(extractPath); }); } -exports.downloadRepository = downloadRepository; /** * Looks up the default branch name */ @@ -1651,7 +1647,6 @@ function getDefaultBranch(authToken, owner, repo, baseUrl) { })); }); } -exports.getDefaultBranch = getDefaultBranch; function downloadArchive(authToken, owner, repo, ref, commit, baseUrl) { return __awaiter(this, void 0, void 0, function* () { const octokit = github.getOctokit(authToken, { @@ -1710,7 +1705,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getInputs = void 0; +exports.getInputs = getInputs; const core = __importStar(__nccwpck_require__(2186)); const fsHelper = __importStar(__nccwpck_require__(7219)); const github = __importStar(__nccwpck_require__(5438)); @@ -1839,7 +1834,6 @@ function getInputs() { return result; }); } -exports.getInputs = getInputs; /***/ }), @@ -1971,7 +1965,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.checkCommitInfo = exports.testRef = exports.getRefSpec = exports.getRefSpecForAllHistory = exports.getCheckoutInfo = exports.tagsRefSpec = void 0; +exports.tagsRefSpec = void 0; +exports.getCheckoutInfo = getCheckoutInfo; +exports.getRefSpecForAllHistory = getRefSpecForAllHistory; +exports.getRefSpec = getRefSpec; +exports.testRef = testRef; +exports.checkCommitInfo = checkCommitInfo; const core = __importStar(__nccwpck_require__(2186)); const github = __importStar(__nccwpck_require__(5438)); const url_helper_1 = __nccwpck_require__(9437); @@ -2025,7 +2024,6 @@ function getCheckoutInfo(git, ref, commit) { return result; }); } -exports.getCheckoutInfo = getCheckoutInfo; function getRefSpecForAllHistory(ref, commit) { const result = ['+refs/heads/*:refs/remotes/origin/*', exports.tagsRefSpec]; if (ref && ref.toUpperCase().startsWith('REFS/PULL/')) { @@ -2034,7 +2032,6 @@ function getRefSpecForAllHistory(ref, commit) { } return result; } -exports.getRefSpecForAllHistory = getRefSpecForAllHistory; function getRefSpec(ref, commit) { if (!ref && !commit) { throw new Error('Args ref and commit cannot both be empty'); @@ -2083,7 +2080,6 @@ function getRefSpec(ref, commit) { return [`+${ref}:${ref}`]; } } -exports.getRefSpec = getRefSpec; /** * Tests whether the initial fetch created the ref at the expected commit */ @@ -2127,7 +2123,6 @@ function testRef(git, ref, commit) { } }); } -exports.testRef = testRef; function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref, commit, baseUrl) { return __awaiter(this, void 0, void 0, function* () { var _a; @@ -2193,7 +2188,6 @@ function checkCommitInfo(token, commitInfo, repositoryOwner, repositoryName, ref } }); } -exports.checkCommitInfo = checkCommitInfo; function fromPayload(path) { return select(github.context.payload, path); } @@ -2218,13 +2212,12 @@ function select(obj, path) { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.escape = void 0; +exports.escape = escape; function escape(value) { return value.replace(/[^a-zA-Z0-9_]/g, x => { return `\\${x}`; }); } -exports.escape = escape; /***/ }), @@ -2267,7 +2260,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.execute = exports.RetryHelper = void 0; +exports.RetryHelper = void 0; +exports.execute = execute; const core = __importStar(__nccwpck_require__(2186)); const defaultMaxAttempts = 3; const defaultMinSeconds = 10; @@ -2319,7 +2313,6 @@ function execute(action) { return yield retryHelper.execute(action); }); } -exports.execute = execute; /***/ }), @@ -2353,7 +2346,11 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.setSafeDirectory = exports.setSshKnownHostsPath = exports.setSshKeyPath = exports.setRepositoryPath = exports.SshKnownHostsPath = exports.SshKeyPath = exports.PostSetSafeDirectory = exports.RepositoryPath = exports.IsPost = void 0; +exports.SshKnownHostsPath = exports.SshKeyPath = exports.PostSetSafeDirectory = exports.RepositoryPath = exports.IsPost = void 0; +exports.setRepositoryPath = setRepositoryPath; +exports.setSshKeyPath = setSshKeyPath; +exports.setSshKnownHostsPath = setSshKnownHostsPath; +exports.setSafeDirectory = setSafeDirectory; const core = __importStar(__nccwpck_require__(2186)); /** * Indicates whether the POST action is running @@ -2381,28 +2378,24 @@ exports.SshKnownHostsPath = core.getState('sshKnownHostsPath'); function setRepositoryPath(repositoryPath) { core.saveState('repositoryPath', repositoryPath); } -exports.setRepositoryPath = setRepositoryPath; /** * Save the SSH key path so the POST action can retrieve the value. */ function setSshKeyPath(sshKeyPath) { core.saveState('sshKeyPath', sshKeyPath); } -exports.setSshKeyPath = setSshKeyPath; /** * Save the SSH known hosts path so the POST action can retrieve the value. */ function setSshKnownHostsPath(sshKnownHostsPath) { core.saveState('sshKnownHostsPath', sshKnownHostsPath); } -exports.setSshKnownHostsPath = setSshKnownHostsPath; /** * Save the set-safe-directory input so the POST action can retrieve the value. */ function setSafeDirectory() { core.saveState('setSafeDirectory', 'true'); } -exports.setSafeDirectory = setSafeDirectory; // Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic. // This is necessary since we don't have a separate entry point. if (!exports.IsPost) { @@ -2441,7 +2434,10 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.isGhes = exports.getServerApiUrl = exports.getServerUrl = exports.getFetchUrl = void 0; +exports.getFetchUrl = getFetchUrl; +exports.getServerUrl = getServerUrl; +exports.getServerApiUrl = getServerApiUrl; +exports.isGhes = isGhes; const assert = __importStar(__nccwpck_require__(9491)); const url_1 = __nccwpck_require__(7310); function getFetchUrl(settings) { @@ -2457,14 +2453,12 @@ function getFetchUrl(settings) { // "origin" is SCHEME://HOSTNAME[:PORT] return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`; } -exports.getFetchUrl = getFetchUrl; function getServerUrl(url) { let urlValue = url && url.trim().length > 0 ? url : process.env['GITHUB_SERVER_URL'] || 'https://github.com'; return new url_1.URL(urlValue); } -exports.getServerUrl = getServerUrl; function getServerApiUrl(url) { let apiUrl = 'https://api.github.com'; if (isGhes(url)) { @@ -2473,12 +2467,10 @@ function getServerApiUrl(url) { } return apiUrl; } -exports.getServerApiUrl = getServerApiUrl; function isGhes(url) { const ghUrl = getServerUrl(url); return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; } -exports.isGhes = isGhes; /***/ }), @@ -2521,7 +2513,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getOrganizationId = void 0; +exports.getOrganizationId = getOrganizationId; const core = __importStar(__nccwpck_require__(2186)); const fs = __importStar(__nccwpck_require__(7147)); /** @@ -2550,7 +2542,6 @@ function getOrganizationId() { } }); } -exports.getOrganizationId = getOrganizationId; /***/ }), diff --git a/package-lock.json b/package-lock.json index 2742b5f..04ea2f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,13 +25,13 @@ "@vercel/ncc": "^0.38.1", "eslint": "^8.57.0", "eslint-plugin-github": "^4.10.2", - "eslint-plugin-jest": "^28.5.0", + "eslint-plugin-jest": "^28.8.2", "jest": "^29.7.0", "jest-circus": "^29.7.0", "js-yaml": "^4.1.0", - "prettier": "^3.2.5", - "ts-jest": "^29.1.2", - "typescript": "^5.4.5" + "prettier": "^3.3.3", + "ts-jest": "^29.2.5", + "typescript": "^5.5.4" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -2080,6 +2080,12 @@ "integrity": "sha512-OH/2E5Fg20h2aPrbe+QL8JZQFko0YZaF+j4mnQ7BGhfavO7OpSLa8a0y9sBwomHdSbkhTS8TQNayBfnW5DwbvQ==", "dev": true }, + "node_modules/async": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.6.tgz", + "integrity": "sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==", + "dev": true + }, "node_modules/available-typed-arrays": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", @@ -2702,6 +2708,21 @@ "node": ">=6.0.0" } }, + "node_modules/ejs": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz", + "integrity": "sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==", + "dev": true, + "dependencies": { + "jake": "^10.8.5" + }, + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/electron-to-chromium": { "version": "1.4.747", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.747.tgz", @@ -3197,18 +3218,18 @@ } }, "node_modules/eslint-plugin-jest": { - "version": "28.5.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.5.0.tgz", - "integrity": "sha512-6np6DGdmNq/eBbA7HOUNV8fkfL86PYwBfwyb8n23FXgJNTR8+ot3smRHjza9LGsBBZRypK3qyF79vMjohIL8eQ==", + "version": "28.8.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.8.2.tgz", + "integrity": "sha512-mC3OyklHmS5i7wYU1rGId9EnxRI8TVlnFG56AE+8U9iRy6zwaNygZR+DsdZuCL0gRG0wVeyzq+uWcPt6yJrrMA==", "dev": true, "dependencies": { - "@typescript-eslint/utils": "^6.0.0 || ^7.0.0" + "@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0" }, "engines": { "node": "^16.10.0 || ^18.12.0 || >=20.0.0" }, "peerDependencies": { - "@typescript-eslint/eslint-plugin": "^6.0.0 || ^7.0.0", + "@typescript-eslint/eslint-plugin": "^6.0.0 || ^7.0.0 || ^8.0.0", "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0", "jest": "*" }, @@ -3573,6 +3594,27 @@ "node": "^10.12.0 || >=12.0.0" } }, + "node_modules/filelist": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz", + "integrity": "sha512-w1cEuf3S+DrLCQL7ET6kz+gmlJdbq9J7yXCSjK/OZCPA+qEN1WyF4ZAf0YYJa4/shHJra2t/d/r8SV4Ji+x+8Q==", + "dev": true, + "dependencies": { + "minimatch": "^5.0.1" + } + }, + "node_modules/filelist/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -4574,6 +4616,46 @@ "set-function-name": "^2.0.1" } }, + "node_modules/jake": { + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/jake/-/jake-10.9.2.tgz", + "integrity": "sha512-2P4SQ0HrLQ+fw6llpLnOaGAvN2Zu6778SJMrCUwns4fOoG9ayrTiZk3VV8sCPkVZF8ab0zksVpS8FDY5pRCNBA==", + "dev": true, + "dependencies": { + "async": "^3.2.3", + "chalk": "^4.0.2", + "filelist": "^1.0.4", + "minimatch": "^3.1.2" + }, + "bin": { + "jake": "bin/cli.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/jake/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/jake/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", @@ -5896,9 +5978,9 @@ } }, "node_modules/prettier": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", - "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", "dev": true, "bin": { "prettier": "bin/prettier.cjs" @@ -6607,28 +6689,30 @@ } }, "node_modules/ts-jest": { - "version": "29.1.2", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.2.tgz", - "integrity": "sha512-br6GJoH/WUX4pu7FbZXuWGKGNDuU7b8Uj77g/Sp7puZV6EXzuByl6JrECvm0MzVzSTkSHWTihsXt+5XYER5b+g==", + "version": "29.2.5", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.2.5.tgz", + "integrity": "sha512-KD8zB2aAZrcKIdGk4OwpJggeLcH1FgrICqDSROWqlnJXGCXK4Mn6FcdK2B6670Xr73lHMG1kHw8R87A0ecZ+vA==", "dev": true, "dependencies": { - "bs-logger": "0.x", - "fast-json-stable-stringify": "2.x", + "bs-logger": "^0.2.6", + "ejs": "^3.1.10", + "fast-json-stable-stringify": "^2.1.0", "jest-util": "^29.0.0", "json5": "^2.2.3", - "lodash.memoize": "4.x", - "make-error": "1.x", - "semver": "^7.5.3", - "yargs-parser": "^21.0.1" + "lodash.memoize": "^4.1.2", + "make-error": "^1.3.6", + "semver": "^7.6.3", + "yargs-parser": "^21.1.1" }, "bin": { "ts-jest": "cli.js" }, "engines": { - "node": "^16.10.0 || ^18.0.0 || >=20.0.0" + "node": "^14.15.0 || ^16.10.0 || ^18.0.0 || >=20.0.0" }, "peerDependencies": { "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/transform": "^29.0.0", "@jest/types": "^29.0.0", "babel-jest": "^29.0.0", "jest": "^29.0.0", @@ -6638,6 +6722,9 @@ "@babel/core": { "optional": true }, + "@jest/transform": { + "optional": true + }, "@jest/types": { "optional": true }, @@ -6649,26 +6736,11 @@ } } }, - "node_modules/ts-jest/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/ts-jest/node_modules/semver": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", - "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, "bin": { "semver": "bin/semver.js" }, @@ -6676,12 +6748,6 @@ "node": ">=10" } }, - "node_modules/ts-jest/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, "node_modules/tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", @@ -6836,9 +6902,9 @@ } }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", "dev": true, "bin": { "tsc": "bin/tsc", diff --git a/package.json b/package.json index b45b792..93121e4 100644 --- a/package.json +++ b/package.json @@ -44,12 +44,12 @@ "@vercel/ncc": "^0.38.1", "eslint": "^8.57.0", "eslint-plugin-github": "^4.10.2", - "eslint-plugin-jest": "^28.5.0", + "eslint-plugin-jest": "^28.8.2", "jest": "^29.7.0", "jest-circus": "^29.7.0", "js-yaml": "^4.1.0", - "prettier": "^3.2.5", - "ts-jest": "^29.1.2", - "typescript": "^5.4.5" + "prettier": "^3.3.3", + "ts-jest": "^29.2.5", + "typescript": "^5.5.4" } } From 6d193bf28034eafb982f37bd894289fe649468fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:04:42 -0400 Subject: [PATCH 09/18] Bump braces from 3.0.2 to 3.0.3 (#1777) Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3. - [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3) --- updated-dependencies: - dependency-name: braces dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package-lock.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 04ea2f4..b65cc27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2247,12 +2247,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -3616,9 +3616,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" From d632683dd7b4114ad314bca15554477dd762a938 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Wed, 25 Sep 2024 13:51:15 -0400 Subject: [PATCH 10/18] Prepare 4.2.0 release (#1878) * Bump package version to 4.1.8 * Add v4.1.8 changelog * Bump version to `4.2.0` --- CHANGELOG.md | 5 +++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 914cab7..877a50f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## v4.2.0 + +* Add Ref and Commit outputs by @lucacome in https://github.com/actions/checkout/pull/1180 +* Dependency updates by @dependabot- https://github.com/actions/checkout/pull/1777, https://github.com/actions/checkout/pull/1872 + ## v4.1.7 * Bump the minor-npm-dependencies group across 1 directory with 4 updates by @dependabot in https://github.com/actions/checkout/pull/1739 * Bump actions/checkout from 3 to 4 by @dependabot in https://github.com/actions/checkout/pull/1697 diff --git a/package-lock.json b/package-lock.json index b65cc27..a84d3bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "checkout", - "version": "4.1.7", + "version": "4.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "checkout", - "version": "4.1.7", + "version": "4.2.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index 93121e4..cdccbfc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "checkout", - "version": "4.1.7", + "version": "4.2.0", "description": "checkout action", "main": "lib/main.js", "scripts": { From de5a000abf73b6f4965bd1bcdf8f8d94a56ea815 Mon Sep 17 00:00:00 2001 From: Orhan Toy Date: Wed, 2 Oct 2024 02:24:28 +0200 Subject: [PATCH 11/18] Check out other refs/* by commit if provided, fall back to ref (#1924) --- __test__/ref-helper.test.ts | 10 ++++++++++ dist/index.js | 4 ++-- src/ref-helper.ts | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/__test__/ref-helper.test.ts b/__test__/ref-helper.test.ts index d3b00b7..5c8d76b 100644 --- a/__test__/ref-helper.test.ts +++ b/__test__/ref-helper.test.ts @@ -77,6 +77,16 @@ describe('ref-helper tests', () => { expect(checkoutInfo.startPoint).toBeFalsy() }) + it('getCheckoutInfo refs/ without commit', async () => { + const checkoutInfo = await refHelper.getCheckoutInfo( + git, + 'refs/non-standard-ref', + '' + ) + expect(checkoutInfo.ref).toBe('refs/non-standard-ref') + expect(checkoutInfo.startPoint).toBeFalsy() + }) + it('getCheckoutInfo unqualified branch only', async () => { git.branchExists = jest.fn(async (remote: boolean, pattern: string) => { return true diff --git a/dist/index.js b/dist/index.js index 2b7dd09..d86415e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2005,8 +2005,8 @@ function getCheckoutInfo(git, ref, commit) { result.ref = ref; } // refs/ - else if (upperRef.startsWith('REFS/') && commit) { - result.ref = commit; + else if (upperRef.startsWith('REFS/')) { + result.ref = commit ? commit : ref; } // Unqualified ref, check for a matching branch or tag else { diff --git a/src/ref-helper.ts b/src/ref-helper.ts index 00a1d27..58f9290 100644 --- a/src/ref-helper.ts +++ b/src/ref-helper.ts @@ -46,8 +46,8 @@ export async function getCheckoutInfo( result.ref = ref } // refs/ - else if (upperRef.startsWith('REFS/') && commit) { - result.ref = commit + else if (upperRef.startsWith('REFS/')) { + result.ref = commit ? commit : ref } // Unqualified ref, check for a matching branch or tag else { From 6b42224f41ee5dfe5395e27c8b2746f1f9955030 Mon Sep 17 00:00:00 2001 From: Joel Ambass Date: Thu, 3 Oct 2024 11:03:35 +0200 Subject: [PATCH 12/18] Add workflow file for publishing releases to immutable action package (#1919) This workflow file publishes new action releases to the immutable action package of the same name as this repo. This is part of the Immutable Actions project which is not yet fully released to the public. First party actions like this one are part of our initial testing of this feature. --- .../workflows/publish-immutable-actions.yml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/publish-immutable-actions.yml diff --git a/.github/workflows/publish-immutable-actions.yml b/.github/workflows/publish-immutable-actions.yml new file mode 100644 index 0000000..87c0207 --- /dev/null +++ b/.github/workflows/publish-immutable-actions.yml @@ -0,0 +1,20 @@ +name: 'Publish Immutable Action Version' + +on: + release: + types: [published] + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + packages: write + + steps: + - name: Checking out + uses: actions/checkout@v4 + - name: Publish + id: publish + uses: actions/publish-immutable-action@0.0.3 From eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 Mon Sep 17 00:00:00 2001 From: Josh Gross Date: Mon, 7 Oct 2024 12:38:04 -0400 Subject: [PATCH 13/18] Prepare 4.2.1 release (#1925) --- CHANGELOG.md | 3 +++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 877a50f..b127df3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v4.2.1 +* Check out other refs/* by commit if provided, fall back to ref by @orhantoy in https://github.com/actions/checkout/pull/1924 + ## v4.2.0 * Add Ref and Commit outputs by @lucacome in https://github.com/actions/checkout/pull/1180 diff --git a/package-lock.json b/package-lock.json index a84d3bd..281b2ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "checkout", - "version": "4.2.0", + "version": "4.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "checkout", - "version": "4.2.0", + "version": "4.2.1", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index cdccbfc..e145004 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "checkout", - "version": "4.2.0", + "version": "4.2.1", "description": "checkout action", "main": "lib/main.js", "scripts": { From 163217dfcd28294438ea1c1c149cfaf66eec283e Mon Sep 17 00:00:00 2001 From: John Wesley Walker III <81404201+jww3@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:07:17 +0200 Subject: [PATCH 14/18] `url-helper.ts` now leverages well-known environment variables. (#1941) * `utl-helper.ts` now leverages well-known environment variables. --------- Co-authored-by: Erez Testiler --- __test__/url-helper.test.ts | 55 ++++++++++++++++++++++++++++++++++ dist/index.js | 50 ++++++++++++++++++++++++------- src/url-helper.ts | 59 +++++++++++++++++++++++++++++-------- 3 files changed, 141 insertions(+), 23 deletions(-) create mode 100644 __test__/url-helper.test.ts diff --git a/__test__/url-helper.test.ts b/__test__/url-helper.test.ts new file mode 100644 index 0000000..27f6606 --- /dev/null +++ b/__test__/url-helper.test.ts @@ -0,0 +1,55 @@ +import * as urlHelper from '../src/url-helper' + +describe('getServerUrl tests', () => { + it('basics', async () => { + // Note that URL::toString will append a trailing / when passed just a domain name ... + expect(urlHelper.getServerUrl().toString()).toBe('https://github.com/') + expect(urlHelper.getServerUrl(' ').toString()).toBe('https://github.com/') + expect(urlHelper.getServerUrl(' ').toString()).toBe('https://github.com/') + expect(urlHelper.getServerUrl('http://contoso.com').toString()).toBe( + 'http://contoso.com/' + ) + expect(urlHelper.getServerUrl('https://contoso.com').toString()).toBe( + 'https://contoso.com/' + ) + expect(urlHelper.getServerUrl('https://contoso.com/').toString()).toBe( + 'https://contoso.com/' + ) + + // ... but can't make that same assumption when passed an URL that includes some deeper path. + expect(urlHelper.getServerUrl('https://contoso.com/a/b').toString()).toBe( + 'https://contoso.com/a/b' + ) + }) +}) + +describe('isGhes tests', () => { + it('basics', async () => { + expect(urlHelper.isGhes()).toBeFalsy() + expect(urlHelper.isGhes('https://github.com')).toBeFalsy() + expect(urlHelper.isGhes('https://contoso.ghe.com')).toBeFalsy() + expect(urlHelper.isGhes('https://test.github.localhost')).toBeFalsy() + expect(urlHelper.isGhes('https://src.onpremise.fabrikam.com')).toBeTruthy() + }) +}) + +describe('getServerApiUrl tests', () => { + it('basics', async () => { + expect(urlHelper.getServerApiUrl()).toBe('https://api.github.com') + expect(urlHelper.getServerApiUrl('https://github.com')).toBe( + 'https://api.github.com' + ) + expect(urlHelper.getServerApiUrl('https://GitHub.com')).toBe( + 'https://api.github.com' + ) + expect(urlHelper.getServerApiUrl('https://contoso.ghe.com')).toBe( + 'https://api.contoso.ghe.com' + ) + expect(urlHelper.getServerApiUrl('https://fabrikam.GHE.COM')).toBe( + 'https://api.fabrikam.ghe.com' + ) + expect( + urlHelper.getServerApiUrl('https://src.onpremise.fabrikam.com') + ).toBe('https://src.onpremise.fabrikam.com/api/v3') + }) +}) diff --git a/dist/index.js b/dist/index.js index d86415e..b0db713 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2454,22 +2454,50 @@ function getFetchUrl(settings) { return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`; } function getServerUrl(url) { - let urlValue = url && url.trim().length > 0 - ? url - : process.env['GITHUB_SERVER_URL'] || 'https://github.com'; - return new url_1.URL(urlValue); + let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com'; + if (hasContent(url, WhitespaceMode.Trim)) { + resolvedUrl = url; + } + return new url_1.URL(resolvedUrl); } function getServerApiUrl(url) { - let apiUrl = 'https://api.github.com'; - if (isGhes(url)) { - const serverUrl = getServerUrl(url); - apiUrl = new url_1.URL(`${serverUrl.origin}/api/v3`).toString(); + if (hasContent(url, WhitespaceMode.Trim)) { + let serverUrl = getServerUrl(url); + if (isGhes(url)) { + serverUrl.pathname = 'api/v3'; + } + else { + serverUrl.hostname = 'api.' + serverUrl.hostname; + } + return pruneSuffix(serverUrl.toString(), '/'); } - return apiUrl; + return process.env['GITHUB_API_URL'] || 'https://api.github.com'; } function isGhes(url) { - const ghUrl = getServerUrl(url); - return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'; + const ghUrl = new url_1.URL(url || process.env['GITHUB_SERVER_URL'] || 'https://github.com'); + const hostname = ghUrl.hostname.trimEnd().toUpperCase(); + const isGitHubHost = hostname === 'GITHUB.COM'; + const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM'); + const isLocalHost = hostname.endsWith('.LOCALHOST'); + return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost; +} +function pruneSuffix(text, suffix) { + if (hasContent(suffix, WhitespaceMode.Preserve) && (text === null || text === void 0 ? void 0 : text.endsWith(suffix))) { + return text.substring(0, text.length - suffix.length); + } + return text; +} +var WhitespaceMode; +(function (WhitespaceMode) { + WhitespaceMode[WhitespaceMode["Trim"] = 0] = "Trim"; + WhitespaceMode[WhitespaceMode["Preserve"] = 1] = "Preserve"; +})(WhitespaceMode || (WhitespaceMode = {})); +function hasContent(text, whitespaceMode) { + let refinedText = text !== null && text !== void 0 ? text : ''; + if (whitespaceMode == WhitespaceMode.Trim) { + refinedText = refinedText.trim(); + } + return refinedText.length > 0; } diff --git a/src/url-helper.ts b/src/url-helper.ts index 64ecbf3..17a0842 100644 --- a/src/url-helper.ts +++ b/src/url-helper.ts @@ -21,26 +21,61 @@ export function getFetchUrl(settings: IGitSourceSettings): string { } export function getServerUrl(url?: string): URL { - let urlValue = - url && url.trim().length > 0 - ? url - : process.env['GITHUB_SERVER_URL'] || 'https://github.com' - return new URL(urlValue) + let resolvedUrl = process.env['GITHUB_SERVER_URL'] || 'https://github.com' + if (hasContent(url, WhitespaceMode.Trim)) { + resolvedUrl = url! + } + + return new URL(resolvedUrl) } export function getServerApiUrl(url?: string): string { - let apiUrl = 'https://api.github.com' + if (hasContent(url, WhitespaceMode.Trim)) { + let serverUrl = getServerUrl(url) + if (isGhes(url)) { + serverUrl.pathname = 'api/v3' + } else { + serverUrl.hostname = 'api.' + serverUrl.hostname + } - if (isGhes(url)) { - const serverUrl = getServerUrl(url) - apiUrl = new URL(`${serverUrl.origin}/api/v3`).toString() + return pruneSuffix(serverUrl.toString(), '/') } - return apiUrl + return process.env['GITHUB_API_URL'] || 'https://api.github.com' } export function isGhes(url?: string): boolean { - const ghUrl = getServerUrl(url) + const ghUrl = new URL( + url || process.env['GITHUB_SERVER_URL'] || 'https://github.com' + ) - return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM' + const hostname = ghUrl.hostname.trimEnd().toUpperCase() + const isGitHubHost = hostname === 'GITHUB.COM' + const isGitHubEnterpriseCloudHost = hostname.endsWith('.GHE.COM') + const isLocalHost = hostname.endsWith('.LOCALHOST') + + return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost +} + +function pruneSuffix(text: string, suffix: string) { + if (hasContent(suffix, WhitespaceMode.Preserve) && text?.endsWith(suffix)) { + return text.substring(0, text.length - suffix.length) + } + return text +} + +enum WhitespaceMode { + Trim, + Preserve +} + +function hasContent( + text: string | undefined, + whitespaceMode: WhitespaceMode +): boolean { + let refinedText = text ?? '' + if (whitespaceMode == WhitespaceMode.Trim) { + refinedText = refinedText.trim() + } + return refinedText.length > 0 } From e3d2460bbb42d7710191569f88069044cfb9d8cf Mon Sep 17 00:00:00 2001 From: John Wesley Walker III <81404201+jww3@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:59:08 +0200 Subject: [PATCH 15/18] Expand unit test coverage (#1946) --- __test__/url-helper.test.ts | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/__test__/url-helper.test.ts b/__test__/url-helper.test.ts index 27f6606..57cb28f 100644 --- a/__test__/url-helper.test.ts +++ b/__test__/url-helper.test.ts @@ -24,13 +24,50 @@ describe('getServerUrl tests', () => { }) describe('isGhes tests', () => { + const pristineEnv = process.env + + beforeEach(() => { + jest.resetModules() + process.env = {...pristineEnv} + }) + + afterAll(() => { + process.env = pristineEnv + }) + it('basics', async () => { + delete process.env['GITHUB_SERVER_URL'] expect(urlHelper.isGhes()).toBeFalsy() expect(urlHelper.isGhes('https://github.com')).toBeFalsy() expect(urlHelper.isGhes('https://contoso.ghe.com')).toBeFalsy() expect(urlHelper.isGhes('https://test.github.localhost')).toBeFalsy() expect(urlHelper.isGhes('https://src.onpremise.fabrikam.com')).toBeTruthy() }) + + it('returns false when the GITHUB_SERVER_URL environment variable is not defined', async () => { + delete process.env['GITHUB_SERVER_URL'] + expect(urlHelper.isGhes()).toBeFalsy() + }) + + it('returns false when the GITHUB_SERVER_URL environment variable is set to github.com', async () => { + process.env['GITHUB_SERVER_URL'] = 'https://github.com' + expect(urlHelper.isGhes()).toBeFalsy() + }) + + it('returns false when the GITHUB_SERVER_URL environment variable is set to a GitHub Enterprise Cloud-style URL', async () => { + process.env['GITHUB_SERVER_URL'] = 'https://contoso.ghe.com' + expect(urlHelper.isGhes()).toBeFalsy() + }) + + it('returns false when the GITHUB_SERVER_URL environment variable has a .localhost suffix', async () => { + process.env['GITHUB_SERVER_URL'] = 'https://mock-github.localhost' + expect(urlHelper.isGhes()).toBeFalsy() + }) + + it('returns true when the GITHUB_SERVER_URL environment variable is set to some other URL', async () => { + process.env['GITHUB_SERVER_URL'] = 'https://src.onpremise.fabrikam.com' + expect(urlHelper.isGhes()).toBeTruthy() + }) }) describe('getServerApiUrl tests', () => { From 11bd71901bbe5b1630ceea73d27597364c9af683 Mon Sep 17 00:00:00 2001 From: John Wesley Walker III <81404201+jww3@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:24:28 +0200 Subject: [PATCH 16/18] Prepare 4.2.2 Release (#1953) * Prepare 4.2.2 Release --------- Co-authored-by: Josh Gross --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b127df3..a96c76e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v4.2.2 +* `url-helper.ts` now leverages well-known environment variables by @jww3 in https://github.com/actions/checkout/pull/1941 +* Expand unit test coverage for `isGhes` by @jww3 in https://github.com/actions/checkout/pull/1946 + ## v4.2.1 * Check out other refs/* by commit if provided, fall back to ref by @orhantoy in https://github.com/actions/checkout/pull/1924 diff --git a/package-lock.json b/package-lock.json index 281b2ea..25753a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "checkout", - "version": "4.2.1", + "version": "4.2.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "checkout", - "version": "4.2.1", + "version": "4.2.2", "license": "MIT", "dependencies": { "@actions/core": "^1.10.1", diff --git a/package.json b/package.json index e145004..5661d70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "checkout", - "version": "4.2.1", + "version": "4.2.2", "description": "checkout action", "main": "lib/main.js", "scripts": { From 3b9b8c884f6b4bb4d5be2779c26374abadae0871 Mon Sep 17 00:00:00 2001 From: The web walker Date: Fri, 8 Nov 2024 23:32:54 +0800 Subject: [PATCH 17/18] docs: update README.md (#1971) Add a scenario where it is necessary to push a commit to a pull request. --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index e1ea032..a43e887 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ - [Checkout pull request HEAD commit instead of merge commit](#Checkout-pull-request-HEAD-commit-instead-of-merge-commit) - [Checkout pull request on closed event](#Checkout-pull-request-on-closed-event) - [Push a commit using the built-in token](#Push-a-commit-using-the-built-in-token) +- [Push a commit to a PR using the built-in token](#Push-a-commit-to-a-PR-using-the-built-in-token) ## Fetch only the root files @@ -288,6 +289,31 @@ jobs: ``` *NOTE:* The user email is `{user.id}+{user.login}@users.noreply.github.com`. See users API: https://api.github.com/users/github-actions%5Bbot%5D +## Push a commit to a PR using the built-in token + +In a pull request trigger, `ref` is required as GitHub Actions checks out in detached HEAD mode, meaning it doesn’t check out your branch by default. + +```yaml +on: pull_request +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - run: | + date > generated.txt + # Note: the following account information will not work on GHES + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add . + git commit -m "generated" + git push +``` +*NOTE:* The user email is `{user.id}+{user.login}@users.noreply.github.com`. See users API: https://api.github.com/users/github-actions%5Bbot%5D + + # License The scripts and documentation in this project are released under the [MIT License](LICENSE) From cbb722410c2e876e24abbe8de2cc27693e501dcb Mon Sep 17 00:00:00 2001 From: Mohammad Ismail <96207520+mouismail@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:41:00 +0100 Subject: [PATCH 18/18] Update README.md (#1977) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a43e887..b0f6224 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ repository: my-org/my-tools path: my-tools ``` -> - If your secondary repository is private you will need to add the option noted in [Checkout multiple repos (private)](#Checkout-multiple-repos-private) +> - If your secondary repository is private or internal you will need to add the option noted in [Checkout multiple repos (private)](#Checkout-multiple-repos-private) ## Checkout multiple repos (nested) @@ -226,7 +226,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ repository: my-org/my-tools path: my-tools ``` -> - If your secondary repository is private you will need to add the option noted in [Checkout multiple repos (private)](#Checkout-multiple-repos-private) +> - If your secondary repository is private or internal you will need to add the option noted in [Checkout multiple repos (private)](#Checkout-multiple-repos-private) ## Checkout multiple repos (private)