From 48c296aa7e0e1aa5ca2fe8a843708675070c4e60 Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Thu, 16 Feb 2023 11:10:37 -0800 Subject: [PATCH] Add Ref and Commit outputs Signed-off-by: Luca Comellini --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++++++++-- action.yml | 5 +++++ dist/index.js | 4 +++- src/git-source-provider.ts | 3 ++- src/main.ts | 1 + 5 files changed, 42 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15996ee..10737aa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -242,7 +242,7 @@ jobs: path: basic - name: Verify basic run: __test__/verify-basic.sh --archive - + test-git-container: runs-on: ubuntu-latest container: bitnami/git:latest @@ -279,4 +279,33 @@ jobs: - name: Fix Checkout v3 uses: actions/checkout@v3 with: - path: v3 \ No newline at end of file + path: v3 + + test-output: + runs-on: ubuntu-latest + steps: + # Clone this repo + - name: Checkout + uses: actions/checkout@v3 + + # 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 + + # needed to make checkout post cleanup succeed + - name: Fix Checkout + uses: actions/checkout@v3 diff --git a/action.yml b/action.yml index 5aa90a7..94ef755 100644 --- a/action.yml +++ b/action.yml @@ -94,6 +94,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 ddf2b3d..c05ab00 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1318,7 +1318,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); } @@ -1848,6 +1849,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 5c98e9f..6524cc1 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -252,7 +252,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'}, '')