-
-
Notifications
You must be signed in to change notification settings - Fork 18
feat(github): Integrate action-prepare-release into Craft repo #667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4887c05
feat(github): Integrate action-prepare-release into Craft repo
BYK fce2ee0
feat(versioning): Add CalVer support and versioning policy configuration
BYK f4402f0
fix bug in changelog config
BYK 0c7df3d
simplify version resolution logic
BYK 6f3d846
fix seer identified bug
BYK 2195ee4
fix another bug
BYK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,242 @@ | ||
| name: "Craft Prepare Release" | ||
| description: "Prepare a new release using Craft" | ||
|
|
||
| inputs: | ||
| version: | ||
| description: > | ||
| Version to release. Can be a semver string (e.g., "1.2.3"), | ||
| a bump type ("major", "minor", "patch"), or "auto" for automatic detection. | ||
| required: false | ||
| merge_target: | ||
| description: Target branch to merge into. Uses the default branch as a fallback. | ||
| required: false | ||
| force: | ||
| description: Force a release even when there are release-blockers | ||
| required: false | ||
| default: "false" | ||
| blocker_label: | ||
| description: Label that blocks releases | ||
| required: false | ||
| default: "release-blocker" | ||
| publish_repo: | ||
| description: Repository for publish issues (owner/repo format) | ||
| required: false | ||
| git_user_name: | ||
| description: Git committer name | ||
| required: false | ||
| git_user_email: | ||
| description: Git committer email | ||
| required: false | ||
| path: | ||
| description: The path that Craft will run inside | ||
| required: false | ||
| default: "." | ||
| craft_config_from_merge_target: | ||
| description: Use the craft config from the merge target branch | ||
| required: false | ||
| default: "false" | ||
|
|
||
| outputs: | ||
| version: | ||
| description: The resolved version being released | ||
| value: ${{ steps.craft.outputs.version }} | ||
| branch: | ||
| description: The release branch name | ||
| value: ${{ steps.craft.outputs.branch }} | ||
| sha: | ||
| description: The commit SHA on the release branch | ||
| value: ${{ steps.craft.outputs.sha }} | ||
| previous_tag: | ||
| description: The tag before this release (for diff links) | ||
| value: ${{ steps.craft.outputs.previous_tag }} | ||
| changelog: | ||
| description: The changelog for this release | ||
| value: ${{ steps.craft.outputs.changelog }} | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - id: killswitch | ||
| name: Check release blockers | ||
| shell: bash | ||
| run: | | ||
| if [[ '${{ inputs.force }}' != 'true' ]] && gh issue list -l '${{ inputs.blocker_label }}' -s open | grep -q '^[0-9]\+[[:space:]]'; then | ||
| echo "::error::Open release-blocking issues found (label: ${{ inputs.blocker_label }}), cancelling release..." | ||
| gh api -X POST repos/:owner/:repo/actions/runs/$GITHUB_RUN_ID/cancel | ||
| fi | ||
|
|
||
| - name: Set git user | ||
| shell: bash | ||
| run: | | ||
| # Use provided values or fall back to triggering actor | ||
| GIT_USER_NAME='${{ inputs.git_user_name }}' | ||
| GIT_USER_EMAIL='${{ inputs.git_user_email }}' | ||
|
|
||
| if [[ -z "$GIT_USER_NAME" ]]; then | ||
| GIT_USER_NAME="${GITHUB_ACTOR}" | ||
| fi | ||
| if [[ -z "$GIT_USER_EMAIL" ]]; then | ||
| GIT_USER_EMAIL="${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | ||
| fi | ||
|
|
||
| echo "GIT_COMMITTER_NAME=${GIT_USER_NAME}" >> $GITHUB_ENV | ||
| echo "GIT_AUTHOR_NAME=${GIT_USER_NAME}" >> $GITHUB_ENV | ||
| echo "EMAIL=${GIT_USER_EMAIL}" >> $GITHUB_ENV | ||
|
|
||
| - name: Download Craft from build artifact | ||
| id: artifact | ||
| if: github.repository == 'getsentry/craft' | ||
| uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 | ||
| continue-on-error: true | ||
| with: | ||
| name: ${{ github.sha }} | ||
| path: /tmp/craft-artifact | ||
|
|
||
| - name: Install Craft from artifact | ||
| if: steps.artifact.outcome == 'success' | ||
| shell: bash | ||
| run: | | ||
| echo "Installing Craft from build artifact..." | ||
| sudo install -m 755 /tmp/craft-artifact/dist/craft /usr/local/bin/craft | ||
|
|
||
| - name: Install Craft from release | ||
| if: steps.artifact.outcome != 'success' | ||
| shell: bash | ||
| run: | | ||
| # Try action ref first (e.g., v2, 2.15.0) | ||
| ACTION_REF="${{ github.action_ref }}" | ||
| CRAFT_URL="https://github.com/getsentry/craft/releases/download/${ACTION_REF}/craft" | ||
|
|
||
| echo "Trying to download Craft from: ${CRAFT_URL}" | ||
|
|
||
| # Fallback to latest if ref doesn't have a release | ||
| if ! curl -sfI "$CRAFT_URL" >/dev/null 2>&1; then | ||
| echo "Release not found for ref '${ACTION_REF}', falling back to latest..." | ||
| CRAFT_URL=$(curl -s "https://api.github.com/repos/getsentry/craft/releases/latest" \ | ||
| | jq -r '.assets[] | select(.name == "craft") | .browser_download_url') | ||
| fi | ||
|
|
||
| echo "Installing Craft from: ${CRAFT_URL}" | ||
| sudo curl -sL -o /usr/local/bin/craft "$CRAFT_URL" | ||
| sudo chmod +x /usr/local/bin/craft | ||
|
|
||
| - name: Craft Prepare | ||
| id: craft | ||
| shell: bash | ||
| env: | ||
| CRAFT_LOG_LEVEL: Debug | ||
| working-directory: ${{ inputs.path }} | ||
| run: | | ||
| # Ensure we have origin/HEAD set | ||
| git remote set-head origin --auto | ||
|
|
||
| # Build command with optional flags | ||
| CRAFT_ARGS="" | ||
| if [[ '${{ inputs.craft_config_from_merge_target }}' == 'true' && -n '${{ inputs.merge_target }}' ]]; then | ||
| CRAFT_ARGS="--config-from ${{ inputs.merge_target }}" | ||
| fi | ||
|
|
||
| # Version is optional - if not provided, Craft uses versioning.policy from config | ||
| VERSION_ARG="" | ||
| if [[ -n '${{ inputs.version }}' ]]; then | ||
| VERSION_ARG="${{ inputs.version }}" | ||
| fi | ||
|
|
||
| craft prepare $VERSION_ARG $CRAFT_ARGS | ||
|
|
||
| - name: Read Craft Targets | ||
| id: craft-targets | ||
| shell: bash | ||
| working-directory: ${{ inputs.path }} | ||
| env: | ||
| CRAFT_LOG_LEVEL: Warn | ||
| run: | | ||
| targets=$(craft targets | jq -r '.[]|" - [ ] \(.)"') | ||
|
|
||
| # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings | ||
| echo "targets<<EOF" >> "$GITHUB_OUTPUT" | ||
| echo "$targets" >> "$GITHUB_OUTPUT" | ||
| echo "EOF" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Request publish | ||
| shell: bash | ||
| run: | | ||
| if [[ '${{ inputs.path }}' == '.' ]]; then | ||
| subdirectory='' | ||
| else | ||
| subdirectory='/${{ inputs.path }}' | ||
| fi | ||
|
|
||
| if [[ -n '${{ inputs.merge_target }}' ]]; then | ||
| merge_target='${{ inputs.merge_target }}' | ||
| else | ||
| merge_target='(default)' | ||
| fi | ||
|
|
||
| # Use resolved version from Craft output | ||
| RESOLVED_VERSION="${{ steps.craft.outputs.version }}" | ||
| if [[ -z "$RESOLVED_VERSION" ]]; then | ||
| echo "::error::Craft did not output a version. This is unexpected." | ||
| exit 1 | ||
| fi | ||
|
|
||
| title="publish: ${GITHUB_REPOSITORY}${subdirectory}@${RESOLVED_VERSION}" | ||
|
|
||
| # Determine publish repo | ||
| PUBLISH_REPO='${{ inputs.publish_repo }}' | ||
| if [[ -z "$PUBLISH_REPO" ]]; then | ||
| PUBLISH_REPO="${GITHUB_REPOSITORY_OWNER}/publish" | ||
| fi | ||
|
|
||
| # Check if issue already exists | ||
| # GitHub only allows search with the "in" operator and this issue search can | ||
| # return non-exact matches. We extract the titles and check with grep -xF | ||
| if gh -R "$PUBLISH_REPO" issue list -S "'$title' in:title" --json title -q '.[] | .title' | grep -qxF -- "$title"; then | ||
| echo "There's already an open publish request, skipped issue creation." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Use Craft outputs for git info | ||
| RELEASE_BRANCH="${{ steps.craft.outputs.branch }}" | ||
| RELEASE_SHA="${{ steps.craft.outputs.sha }}" | ||
| PREVIOUS_TAG="${{ steps.craft.outputs.previous_tag }}" | ||
|
|
||
| # Fall back to HEAD if no previous tag | ||
| if [[ -z "$PREVIOUS_TAG" ]]; then | ||
| PREVIOUS_TAG="HEAD" | ||
| fi | ||
|
|
||
| # Build changelog section if available | ||
| CHANGELOG='${{ steps.craft.outputs.changelog }}' | ||
| if [[ -n "$CHANGELOG" ]]; then | ||
| CHANGELOG_SECTION=" | ||
| --- | ||
|
|
||
| <details> | ||
| <summary>📋 Changelog</summary> | ||
|
|
||
| ${CHANGELOG} | ||
|
|
||
| </details>" | ||
| else | ||
| CHANGELOG_SECTION="" | ||
| fi | ||
|
|
||
| body="Requested by: @${GITHUB_ACTOR} | ||
|
|
||
| Merge target: ${merge_target} | ||
|
|
||
| Quick links: | ||
| - [View changes](https://github.com/${GITHUB_REPOSITORY}/compare/${PREVIOUS_TAG}...${RELEASE_BRANCH}) | ||
| - [View check runs](https://github.com/${GITHUB_REPOSITORY}/commit/${RELEASE_SHA}/checks/) | ||
|
|
||
| Assign the **accepted** label to this issue to approve the release. | ||
| To retract the release, the person requesting it must leave a comment containing \`#retract\` on a line by itself under this issue. | ||
|
|
||
| ### Targets | ||
|
|
||
| ${{ steps.craft-targets.outputs.targets }} | ||
|
|
||
| Checked targets will be skipped (either already published or user-requested skip). Uncheck to retry a target. | ||
| ${CHANGELOG_SECTION}" | ||
| gh issue create -R "$PUBLISH_REPO" --title "$title" --body "$body" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.