|
| 1 | +name: Release & Publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag_name: |
| 7 | + description: Release tag to create, for example v1.0.3 |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + target_commitish: |
| 11 | + description: Branch or commit SHA the tag should point to |
| 12 | + required: true |
| 13 | + default: rider-test # main |
| 14 | + type: string |
| 15 | + prerelease: |
| 16 | + description: Mark the GitHub release as a prerelease |
| 17 | + required: true |
| 18 | + default: true |
| 19 | + type: boolean |
| 20 | + draft: |
| 21 | + description: Create the GitHub release as a draft |
| 22 | + required: true |
| 23 | + default: false |
| 24 | + type: boolean |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: write |
| 28 | + |
| 29 | +jobs: |
| 30 | + build: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + |
| 33 | + outputs: |
| 34 | + tag_name: ${{ steps.release_meta.outputs.tag_name }} |
| 35 | + release_name: ${{ steps.release_meta.outputs.release_name }} |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Checkout code |
| 39 | + uses: actions/checkout@v5 |
| 40 | + with: |
| 41 | + ref: ${{ inputs.target_commitish }} |
| 42 | + |
| 43 | + - name: Setup Node.js |
| 44 | + uses: actions/setup-node@v6 |
| 45 | + with: |
| 46 | + node-version: '24.x' |
| 47 | + cache: 'npm' |
| 48 | + |
| 49 | + - name: Install dependencies |
| 50 | + run: npm install |
| 51 | + |
| 52 | + - name: Validate tag matches package version |
| 53 | + id: release_meta |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + PACKAGE_VERSION=$(node -p "require('./package.json').version") |
| 57 | + EXPECTED_TAG="v${PACKAGE_VERSION}" |
| 58 | + if [ "${{ inputs.tag_name }}" != "$EXPECTED_TAG" ]; then |
| 59 | + echo "Expected release tag $EXPECTED_TAG for package version $PACKAGE_VERSION, got ${{ inputs.tag_name }}" >&2 |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | +
|
| 63 | + echo "tag_name=${{ inputs.tag_name }}" >> "$GITHUB_OUTPUT" |
| 64 | + echo "release_name=SL-VScode Plugin ${PACKAGE_VERSION} Release" >> "$GITHUB_OUTPUT" |
| 65 | +
|
| 66 | + - name: Compile extension |
| 67 | + run: npm run vscode:prepublish |
| 68 | + |
| 69 | + - name: Install vsce |
| 70 | + run: npm install -g @vscode/vsce |
| 71 | + |
| 72 | + - name: Package extension |
| 73 | + run: vsce package |
| 74 | + |
| 75 | + - name: Get package filename |
| 76 | + id: package |
| 77 | + shell: bash |
| 78 | + run: | |
| 79 | + PACKAGE_FILE=$(ls *.vsix | head -1) |
| 80 | + echo "filename=$PACKAGE_FILE" >> "$GITHUB_OUTPUT" |
| 81 | +
|
| 82 | + - name: Upload VSIX artifact |
| 83 | + uses: actions/upload-artifact@v4 |
| 84 | + with: |
| 85 | + name: vscode-extension-release-${{ github.run_id }} |
| 86 | + path: ${{ steps.package.outputs.filename }} |
| 87 | + retention-days: 30 |
| 88 | + |
| 89 | + release_notes: |
| 90 | + name: Generate release notes |
| 91 | + needs: build |
| 92 | + uses: ./.github/workflows/generate-release-notes.yml |
| 93 | + permissions: |
| 94 | + contents: read |
| 95 | + with: |
| 96 | + tag_name: ${{ needs.build.outputs.tag_name }} |
| 97 | + target_commitish: ${{ inputs.target_commitish }} |
| 98 | + |
| 99 | + release: |
| 100 | + name: Publish release |
| 101 | + needs: [build, release_notes] |
| 102 | + runs-on: ubuntu-latest |
| 103 | + |
| 104 | + steps: |
| 105 | + - name: Checkout target branch |
| 106 | + uses: actions/checkout@v5 |
| 107 | + with: |
| 108 | + ref: ${{ inputs.target_commitish }} |
| 109 | + |
| 110 | + - name: Write release notes file |
| 111 | + shell: bash |
| 112 | + env: |
| 113 | + RELEASE_NOTES: ${{ needs.release_notes.outputs.release_notes }} |
| 114 | + run: | |
| 115 | + printf '%s\n' "$RELEASE_NOTES" > release_notes.md |
| 116 | +
|
| 117 | + - name: Update CHANGELOG.md |
| 118 | + shell: bash |
| 119 | + run: | |
| 120 | + VERSION="${{ needs.build.outputs.tag_name }}" |
| 121 | + VERSION="${VERSION#v}" |
| 122 | + RELEASE_DATE=$(date -u +%Y-%m-%d) |
| 123 | +
|
| 124 | + { |
| 125 | + echo "## [${VERSION}] - ${RELEASE_DATE}" |
| 126 | + echo |
| 127 | + cat release_notes.md |
| 128 | + echo |
| 129 | + } > changelog_entry.md |
| 130 | +
|
| 131 | + awk ' |
| 132 | + BEGIN { inserted = 0 } |
| 133 | + /^## \[/ && inserted == 0 { |
| 134 | + while ((getline line < "changelog_entry.md") > 0) print line |
| 135 | + close("changelog_entry.md") |
| 136 | + print "" |
| 137 | + inserted = 1 |
| 138 | + } |
| 139 | + { print } |
| 140 | + END { |
| 141 | + if (inserted == 0) { |
| 142 | + print "" |
| 143 | + while ((getline line < "changelog_entry.md") > 0) print line |
| 144 | + close("changelog_entry.md") |
| 145 | + } |
| 146 | + } |
| 147 | + ' CHANGELOG.md > CHANGELOG.new.md |
| 148 | +
|
| 149 | + mv CHANGELOG.new.md CHANGELOG.md |
| 150 | +
|
| 151 | + - name: Commit and push changelog update |
| 152 | + shell: bash |
| 153 | + run: | |
| 154 | + TARGET_BRANCH="${{ inputs.target_commitish }}" |
| 155 | + TARGET_BRANCH="${TARGET_BRANCH#refs/heads/}" |
| 156 | +
|
| 157 | + if ! git ls-remote --exit-code --heads origin "$TARGET_BRANCH" > /dev/null; then |
| 158 | + echo "target_commitish must be a branch name (or refs/heads/<branch>) to update CHANGELOG.md" >&2 |
| 159 | + echo "Received: ${{ inputs.target_commitish }}" >&2 |
| 160 | + exit 1 |
| 161 | + fi |
| 162 | +
|
| 163 | + git config user.name "github-actions[bot]" |
| 164 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 165 | +
|
| 166 | + git add CHANGELOG.md |
| 167 | +
|
| 168 | + if git diff --cached --quiet; then |
| 169 | + echo "No changelog changes to commit" |
| 170 | + exit 0 |
| 171 | + fi |
| 172 | +
|
| 173 | + git commit -m "docs: update changelog for ${{ needs.build.outputs.tag_name }}" |
| 174 | + git push origin HEAD:$TARGET_BRANCH |
| 175 | +
|
| 176 | + - name: Download VSIX artifact |
| 177 | + uses: actions/download-artifact@v4 |
| 178 | + with: |
| 179 | + name: vscode-extension-release-${{ github.run_id }} |
| 180 | + |
| 181 | + - name: Get package filename |
| 182 | + id: package |
| 183 | + shell: bash |
| 184 | + run: | |
| 185 | + PACKAGE_FILE=$(ls *.vsix | head -1) |
| 186 | + echo "filename=$PACKAGE_FILE" >> "$GITHUB_OUTPUT" |
| 187 | +
|
| 188 | + # - name: Create GitHub release |
| 189 | + # uses: secondlife-3p/action-gh-release@v1 |
| 190 | + # with: |
| 191 | + # tag_name: ${{ needs.build.outputs.tag_name }} |
| 192 | + # target_commitish: ${{ inputs.target_commitish }} |
| 193 | + # name: ${{ needs.build.outputs.release_name }} |
| 194 | + # prerelease: ${{ inputs.prerelease }} |
| 195 | + # draft: ${{ inputs.draft }} |
| 196 | + # body_path: release_notes.md |
| 197 | + # files: ${{ steps.package.outputs.filename }} |
0 commit comments