Skip to content

Commit 54bb734

Browse files
committed
Add Ref and Commit outputs
1 parent ac59398 commit 54bb734

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

.github/workflows/test.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jobs:
205205
path: basic
206206
- name: Verify basic
207207
run: __test__/verify-basic.sh --archive
208-
208+
209209
test-git-container:
210210
runs-on: ubuntu-latest
211211
container: bitnami/git:latest
@@ -242,4 +242,33 @@ jobs:
242242
- name: Fix Checkout v3
243243
uses: actions/checkout@v3
244244
with:
245-
path: v3
245+
path: v3
246+
247+
test-output:
248+
runs-on: ubuntu-latest
249+
steps:
250+
# Clone this repo
251+
- name: Checkout
252+
uses: actions/checkout@v3
253+
254+
# Basic checkout using git
255+
- name: Checkout basic
256+
id: checkout
257+
uses: ./
258+
with:
259+
ref: test-data/v2/basic
260+
261+
# Verify output
262+
- name: Verify output
263+
run: |
264+
echo "Commit: ${{ steps.checkout.outputs.commit }}"
265+
echo "Ref: ${{ steps.checkout.outputs.ref }}"
266+
267+
if [ "${{ steps.checkout.outputs.ref }}" != "test-data/v2/basic" ]; then
268+
echo "Expected ref to be test-data/v2/basic"
269+
exit 1
270+
fi
271+
272+
# needed to make checkout post cleanup succeed
273+
- name: Fix Checkout
274+
uses: actions/checkout@v3

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ inputs:
7474
github-server-url:
7575
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
7676
required: false
77+
outputs:
78+
ref:
79+
description: 'The branch, tag or SHA that was checked out'
80+
commit:
81+
description: 'The commit SHA that was checked out'
7782
runs:
7883
using: node16
7984
main: dist/index.js

dist/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4658,6 +4658,7 @@ function run() {
46584658
coreCommand.issueCommand('add-matcher', {}, path.join(__dirname, 'problem-matcher.json'));
46594659
// Get sources
46604660
yield gitSourceProvider.getSource(sourceSettings);
4661+
core.setOutput('ref', sourceSettings.ref);
46614662
}
46624663
finally {
46634664
// Unregister problem matcher
@@ -32022,7 +32023,8 @@ function getSource(settings) {
3202232023
// Get commit information
3202332024
const commitInfo = yield git.log1();
3202432025
// Log commit sha
32025-
yield git.log1("--format='%H'");
32026+
const commitSHA = yield git.log1('--format=%H');
32027+
core.setOutput('commit', commitSHA.trim());
3202632028
// Check for incorrect pull request merge commit
3202732029
yield refHelper.checkCommitInfo(settings.authToken, commitInfo, settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.githubServerUrl);
3202832030
}

src/git-source-provider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
225225
const commitInfo = await git.log1()
226226

227227
// Log commit sha
228-
await git.log1("--format='%H'")
228+
const commitSHA = await git.log1('--format=%H')
229+
core.setOutput('commit', commitSHA.trim())
229230

230231
// Check for incorrect pull request merge commit
231232
await refHelper.checkCommitInfo(

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ async function run(): Promise<void> {
1919

2020
// Get sources
2121
await gitSourceProvider.getSource(sourceSettings)
22+
core.setOutput('ref', sourceSettings.ref)
2223
} finally {
2324
// Unregister problem matcher
2425
coreCommand.issueCommand('remove-matcher', {owner: 'checkout-git'}, '')

0 commit comments

Comments
 (0)