Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Comellini <luca.com@gmail.com>2024-09-05 08:57:13 -0700
committerGitHub <noreply@github.com>2024-09-05 11:57:13 -0400
commitc16730ea86aff221caa4464dfa9ec944a94e6b36 (patch)
treed8f764819a838daa3508f71c980eecc82e87d5a9
parent5124486016880e81b011eeffffe04d4b918740ec (diff)
Add Ref and Commit outputs (#1180)
Signed-off-by: Luca Comellini <luca.com@gmail.com>
-rw-r--r--.github/workflows/test.yml34
-rw-r--r--action.yml5
-rw-r--r--dist/index.js4
-rw-r--r--src/git-source-provider.ts3
-rw-r--r--src/main.ts1
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<void> {
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<void> {
// Get sources
await gitSourceProvider.getSource(sourceSettings)
+ core.setOutput('ref', sourceSettings.ref)
} finally {
// Unregister problem matcher
coreCommand.issueCommand('remove-matcher', {owner: 'checkout-git'}, '')