Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 72 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: "Release"

on:
pull_request:
types: [closed]
push:
branches: [main]
paths:
- '.sampo/changesets/**'
workflow_dispatch:

permissions:
Expand All @@ -16,15 +17,77 @@ concurrency:
cancel-in-progress: false

jobs:
resolve-release-context:
name: Resolve release context
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
should-release: ${{ steps.resolve.outputs.should-release }}
bump-type: ${{ steps.resolve.outputs.bump-type }}
Comment on lines +27 to +28
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unused bump-type output

bump-type is declared as a job output and set unconditionally to "" in every code path, but no downstream job (check-release-label, release, notify-*) ever reads needs.resolve-release-context.outputs.bump-type. Per the simplicity rule "has no superfluous parts," consider removing it — or add a comment explaining it is a placeholder for future bump-label support if that's the intent.

Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/release.yml
Line: 27-28

Comment:
**Unused `bump-type` output**

`bump-type` is declared as a job output and set unconditionally to `""` in every code path, but no downstream job (`check-release-label`, `release`, `notify-*`) ever reads `needs.resolve-release-context.outputs.bump-type`. Per the simplicity rule "has no superfluous parts," consider removing it — or add a comment explaining it is a placeholder for future bump-label support if that's the intent.

How can I resolve this? If you propose a fix, please make it concise.

steps:
- name: Resolve release request
id: resolve
env:
GH_TOKEN: ${{ github.token }}
EVENT_NAME: ${{ github.event_name }}
CURRENT_REF: ${{ github.ref }}
DEFAULT_BRANCH: main
PUSH_SHA: ${{ github.sha }}
PUSH_HEAD_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: |
set -euo pipefail

SHOULD_RELEASE=false
BUMP_TYPE=""

if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
if [ "$CURRENT_REF" != "refs/heads/$DEFAULT_BRANCH" ]; then
echo "::notice::Skipping release because workflow_dispatch must be run on $DEFAULT_BRANCH, got $CURRENT_REF."
else
SHOULD_RELEASE=true
echo "✓ Manual release requested on $DEFAULT_BRANCH"
fi

echo "should-release=$SHOULD_RELEASE" >> "$GITHUB_OUTPUT"
echo "bump-type=$BUMP_TYPE" >> "$GITHUB_OUTPUT"
exit 0
fi

if [[ "${PUSH_HEAD_COMMIT_MESSAGE:-}" == *"[version bump]"* || "${PUSH_HEAD_COMMIT_MESSAGE:-}" == "Bump version to "* || "${PUSH_HEAD_COMMIT_MESSAGE:-}" == "chore: Release v"* || "${PUSH_HEAD_COMMIT_MESSAGE:-}" == "chore: release "* ]]; then
echo "::notice::Skipping release for the automated version bump commit."
echo "should-release=false" >> "$GITHUB_OUTPUT"
echo "bump-type=" >> "$GITHUB_OUTPUT"
exit 0
fi

PRS_JSON=$(gh api "repos/${{ github.repository }}/commits/$PUSH_SHA/pulls")
MATCHING_PR_COUNT=$(echo "$PRS_JSON" | jq --arg branch "$DEFAULT_BRANCH" '[.[] | select(.merged_at != null and .base.ref == $branch and (.labels | map(.name) | index("release")))] | length')

if [ "$MATCHING_PR_COUNT" -eq 0 ]; then
ASSOCIATED_PRS=$(echo "$PRS_JSON" | jq -r '[.[].number | tostring] | join(", ")')
if [ -n "$ASSOCIATED_PRS" ]; then
echo "::notice::Skipping release because push $PUSH_SHA is associated with PR(s) [$ASSOCIATED_PRS], but none currently have the release label."
else
echo "::notice::Skipping release because push $PUSH_SHA is not associated with a merged PR to $DEFAULT_BRANCH that has the release label."
fi
echo "should-release=false" >> "$GITHUB_OUTPUT"
echo "bump-type=" >> "$GITHUB_OUTPUT"
exit 0
fi

RELEASE_PRS=$(echo "$PRS_JSON" | jq -r --arg branch "$DEFAULT_BRANCH" '[.[] | select(.merged_at != null and .base.ref == $branch and (.labels | map(.name) | index("release"))) | "#\(.number)"] | join(", ")')
echo "✓ Release requested by push $PUSH_SHA via $RELEASE_PRS"
echo "should-release=true" >> "$GITHUB_OUTPUT"
echo "bump-type=" >> "$GITHUB_OUTPUT"

check-release-label:
name: Check for release label
needs: resolve-release-context
runs-on: ubuntu-latest
# Run when PR with 'release' label is merged to main
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'release'))
if: needs.resolve-release-context.outputs.should-release == 'true'
outputs:
should-release: ${{ steps.check.outputs.should-release }}
steps:
Expand Down Expand Up @@ -60,11 +123,11 @@ jobs:

release:
name: Release and publish
needs: [check-release-label, notify-approval-needed]
needs: [resolve-release-context, check-release-label, notify-approval-needed]
runs-on: ubuntu-latest
# Use `always()` to ensure the job runs even if notify-approval-needed is skipped,
# but still depend on it to access `needs.notify-approval-needed.outputs.slack_ts`
if: always() && needs.check-release-label.outputs.should-release == 'true'
if: always() && needs.resolve-release-context.outputs.should-release == 'true' && needs.check-release-label.outputs.should-release == 'true'
environment: "Release" # This will require an approval from a maintainer, they are notified in Slack above
permissions:
contents: write
Expand Down
Loading