|
| 1 | +name: Pre-release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [labeled] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + pre-release: |
| 13 | + if: >- |
| 14 | + github.event.label.name == 'pre-release' && |
| 15 | + startsWith(github.event.pull_request.head.ref, 'release-please--') |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v6 |
| 19 | + with: |
| 20 | + ref: main |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Extract version from PR title |
| 24 | + id: version |
| 25 | + run: | |
| 26 | + TITLE="${{ github.event.pull_request.title }}" |
| 27 | + # Extract version from "chore(main): release X.Y.Z" |
| 28 | + VERSION=$(echo "$TITLE" | grep -oP '\d+\.\d+\.\d+') |
| 29 | + if [ -z "$VERSION" ]; then |
| 30 | + echo "::error::Could not extract version from PR title: $TITLE" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + echo "base_version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 34 | +
|
| 35 | + - name: Determine RC number |
| 36 | + id: rc |
| 37 | + run: | |
| 38 | + VERSION="${{ steps.version.outputs.base_version }}" |
| 39 | + # Find existing rc tags for this version and increment |
| 40 | + LAST_RC=$(git tag -l "v${VERSION}-rc.*" | sort -V | tail -1 | grep -oP 'rc\.\K\d+' || echo "0") |
| 41 | + NEXT_RC=$((LAST_RC + 1)) |
| 42 | + TAG="v${VERSION}-rc.${NEXT_RC}" |
| 43 | + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" |
| 44 | + echo "rc_number=${NEXT_RC}" >> "$GITHUB_OUTPUT" |
| 45 | +
|
| 46 | + - uses: pnpm/action-setup@v4 |
| 47 | + with: |
| 48 | + version: 9 |
| 49 | + |
| 50 | + - uses: actions/setup-node@v6 |
| 51 | + with: |
| 52 | + node-version: 24 |
| 53 | + cache: 'pnpm' |
| 54 | + |
| 55 | + - name: Install dependencies |
| 56 | + run: pnpm install |
| 57 | + |
| 58 | + - name: Build plugin |
| 59 | + run: pnpm run build |
| 60 | + |
| 61 | + - name: Create release package |
| 62 | + run: | |
| 63 | + TAG="${{ steps.rc.outputs.tag }}" |
| 64 | + VERSION="${TAG#v}" |
| 65 | + RELEASE_DIR="LetUsReShade" |
| 66 | + ZIP_NAME="LetUsReShade_v${VERSION}.zip" |
| 67 | +
|
| 68 | + mkdir -p "${RELEASE_DIR}" |
| 69 | +
|
| 70 | + cp -r dist "${RELEASE_DIR}/" |
| 71 | + cp -r defaults "${RELEASE_DIR}/" |
| 72 | + cp main.py "${RELEASE_DIR}/" |
| 73 | + cp package.json "${RELEASE_DIR}/" |
| 74 | + cp plugin.json "${RELEASE_DIR}/" |
| 75 | + cp LICENSE "${RELEASE_DIR}/" |
| 76 | + cp README.md "${RELEASE_DIR}/" |
| 77 | +
|
| 78 | + zip -r "${ZIP_NAME}" "${RELEASE_DIR}" |
| 79 | +
|
| 80 | + echo "ZIP_NAME=${ZIP_NAME}" >> "$GITHUB_ENV" |
| 81 | +
|
| 82 | + - name: Fetch release notes from release-please PR |
| 83 | + id: notes |
| 84 | + env: |
| 85 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + run: | |
| 87 | + # Fetch the release-please PR body and extract the clean changelog section |
| 88 | + # The PR body format is: |
| 89 | + # :robot: I have created a release *beep* *boop* |
| 90 | + # --- |
| 91 | + # ## [1.9.0](...) (2026-05-19) |
| 92 | + # ... |
| 93 | + # --- |
| 94 | + # This PR was generated with [Release Please]... |
| 95 | + PR_BODY=$(gh pr view ${{ github.event.pull_request.number }} --json body -q .body) |
| 96 | +
|
| 97 | + # Extract content between first '---' and last '---' (the clean changelog) |
| 98 | + CHANGELOG=$(echo "$PR_BODY" | awk '/^---$/{if(!found){found=1;next}} /^---$/{exit} found') |
| 99 | +
|
| 100 | + # Prepend the RC tag to the release notes |
| 101 | + { |
| 102 | + echo "**${{ steps.rc.outputs.tag }}**" |
| 103 | + echo "" |
| 104 | + echo "$CHANGELOG" |
| 105 | + } > release_notes.md |
| 106 | +
|
| 107 | + echo "notes_file=release_notes.md" >> "$GITHUB_OUTPUT" |
| 108 | +
|
| 109 | + - name: Create pre-release |
| 110 | + env: |
| 111 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + run: | |
| 113 | + TAG="${{ steps.rc.outputs.tag }}" |
| 114 | + gh release create "$TAG" \ |
| 115 | + "$ZIP_NAME" \ |
| 116 | + --title "$TAG" \ |
| 117 | + --prerelease \ |
| 118 | + --notes-file "${{ steps.notes.outputs.notes_file }}" |
| 119 | +
|
| 120 | + - name: Find existing bot comment |
| 121 | + uses: peter-evans/find-comment@v3 |
| 122 | + id: find-comment |
| 123 | + with: |
| 124 | + issue-number: ${{ github.event.pull_request.number }} |
| 125 | + comment-author: 'github-actions[bot]' |
| 126 | + body-includes: '<!-- pre-release -->' |
| 127 | + |
| 128 | + - name: Post or update comment |
| 129 | + uses: peter-evans/create-or-update-comment@v4 |
| 130 | + with: |
| 131 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 132 | + issue-number: ${{ github.event.pull_request.number }} |
| 133 | + edit-mode: replace |
| 134 | + body: | |
| 135 | + <!-- pre-release --> |
| 136 | + **Pre-release: `${{ steps.rc.outputs.tag }}`** |
| 137 | +
|
| 138 | + [Download from releases](${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ steps.rc.outputs.tag }}) |
| 139 | +
|
| 140 | + *Created: ${{ github.event.pull_request.updated_at }}* |
| 141 | +
|
| 142 | + - name: Remove pre-release label |
| 143 | + uses: actions/github-script@v7 |
| 144 | + with: |
| 145 | + script: | |
| 146 | + await github.rest.issues.removeLabel({ |
| 147 | + owner: context.repo.owner, |
| 148 | + repo: context.repo.repo, |
| 149 | + issue_number: context.payload.pull_request.number, |
| 150 | + name: 'pre-release' |
| 151 | + }); |
0 commit comments