Skip to content

Commit 7b8c609

Browse files
committed
switch to tag for pull requests.
1 parent e84bda9 commit 7b8c609

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

.github/workflows/test-negative.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
release_name="${PREFIX}$(git rev-parse --short HEAD)"
2323
gh release create ${release_name} --prerelease --target ${{ github.sha }} --notes "Created by ${{ github.workflow }} (will be automatically deleted)."
2424
echo "name=${release_name}" > $GITHUB_OUTPUT
25-
echo "id=$(gh release view ${release_name} --json id -q '.id')" >> $GITHUB_OUTPUT
25+
echo "tag=$(gh release view ${release_name} --json tagName -q '.tagName')" >> $GITHUB_OUTPUT
2626
env:
2727
# Below is the main difference between this workflow's positive counterpart.
2828
# The action will not pick up a comment because the provided 'include_regex' will not be able to match it.
@@ -31,7 +31,7 @@ jobs:
3131

3232
outputs:
3333
name: ${{ steps.create-release.outputs.name }}
34-
id: ${{ steps.create-release.outputs.id }}
34+
tag: ${{ steps.create-release.outputs.tag }}
3535

3636
assert:
3737
runs-on: ubuntu-latest
@@ -42,7 +42,7 @@ jobs:
4242

4343
- uses: ./
4444
with:
45-
release_id: ${{ needs.create-release.outputs.id}}
45+
tag: ${{ needs.create-release.outputs.tag }}
4646
include_regex: "/v0\\.0\\.0-test\\.include\\.*./g" # Should not find a comment
4747

4848
- name: Find Comment (should fail)

.github/workflows/test-positive.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
release_name="${PREFIX}$(git rev-parse --short HEAD)"
2323
gh release create ${release_name} --prerelease --target ${{ github.sha }} --notes "Created by ${{ github.workflow }} (will be automatically deleted)."
2424
echo "name=${release_name}" > $GITHUB_OUTPUT
25-
echo "id=$(gh release view ${release_name} --json id -q '.id')" >> $GITHUB_OUTPUT
25+
echo "tag=$(gh release view ${release_name} --json tagName -q '.tagName')" >> $GITHUB_OUTPUT
2626
env:
2727
# Below is the main difference between this workflow's negative counterpart.
2828
# The action _will_ pick up a comment because the provided 'include_regex' will be able to match it.
@@ -31,7 +31,7 @@ jobs:
3131

3232
outputs:
3333
name: ${{ steps.create-release.outputs.name }}
34-
id: ${{ steps.create-release.outputs.id }}
34+
tag: ${{ steps.create-release.outputs.tag }}
3535

3636
assert:
3737
runs-on: ubuntu-latest
@@ -42,7 +42,7 @@ jobs:
4242

4343
- uses: ./
4444
with:
45-
release_id: ${{ needs.create-release.outputs.id}}
45+
tag: ${{ needs.create-release.outputs.tag }}
4646
include_regex: "/v0\\.0\\.0-test\\.include\\.*./g" # Should not find a comment
4747

4848
- name: Find Comment (should pass)

action.yml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ inputs:
1313
required: false
1414
description: "JavaScript regex used to filter releases."
1515
default: "/.*/g"
16-
release_id:
16+
tag:
1717
required: false
18-
description: "The ID of the release. Defaults to `github.event.release.id`."
18+
description: "The git tag used to determine the release. If omitted, the release will be determined from `github.event.release.id`."
1919
default: ""
2020
runs:
2121
using: "composite"
2222
steps:
2323
- uses: actions/github-script@v7
2424
env:
25-
INPUT_RELEASE_ID: ${{ inputs.release_id }}
25+
TAG: ${{ inputs.release_id }}
2626
with:
2727
result-encoding: string
2828
retries: ${{ inputs.retries }}
2929
script: |
30-
const { INPUT_RELEASE_ID } = process.env
30+
const { TAG } = process.env
3131
3232
switch(context.eventName) {
3333
case ('release'):
3434
break;
3535
case ('workflow_run'):
3636
core.warning("This action is designed to run on 'release', not 'workflow_run'. Even when corresponding to a workflow triggered by 'release', 'workflow_run' may not work due to its event context schema.");
3737
break;
38-
case ('pull_request' && INPUT_RELEASE_ID):
39-
core.error("This action is meant to only run on 'release'. 'pull_request' is reserved for testing, and 'release_id' was not supplied.");
38+
case ('pull_request' && INPUT_RELEASE_NAME):
39+
core.error("This action is meant to only run on 'release'. 'pull_request' is reserved for testing, and 'tag' was not supplied.");
4040
break;
4141
case ('pull_request'):
4242
core.warning("This action is meant to only run on 'release'. 'pull_request' is reserved for testing.");
@@ -76,22 +76,24 @@ runs:
7676
});
7777
}
7878
79-
releaseID = INPUT_RELEASE_ID;
80-
if (!releaseID) {
81-
console.log("Fetching release ID from GitHub context...");
82-
releaseID = context.payload.release.id;
83-
console.log(`Release ID: releaseID`);
79+
releaseTag = TAG;
80+
releaseID = null;
81+
82+
if (releaseTag) {
83+
currentReleaseResponse = await github.rest.repos.getReleaseByTag({
84+
owner: context.repo.owner,
85+
repo: context.repo.repo,
86+
releaseTag,
87+
});
8488
} else {
85-
console.log(`Using supplied 'release_id': ${releaseID}`);
89+
releaseID = context.payload.release.id;
90+
currentReleaseResponse = await github.rest.repos.getRelease({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
releaseID,
94+
});
8695
}
8796
88-
// Fetching details of the current release
89-
currentReleaseResponse = await github.rest.repos.getRelease({
90-
owner: context.repo.owner,
91-
repo: context.repo.repo,
92-
releaseID,
93-
});
94-
9597
currentRelease = currentReleaseResponse.data;
9698
9799
// Extracting tag name and target branch from the current release

0 commit comments

Comments
 (0)