Release #15
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
| name: Release | |
| on: | |
| workflow_run: | |
| workflows: | |
| - CI | |
| types: | |
| - completed | |
| branches: | |
| - main | |
| - master | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: release-${{ github.event.workflow_run.head_sha || github.sha }} | |
| cancel-in-progress: false | |
| jobs: | |
| build-and-publish: | |
| if: > | |
| github.event_name == 'workflow_dispatch' || | |
| github.event.workflow_run.conclusion == 'success' | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout release commit | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha || github.sha }} | |
| fetch-depth: 0 | |
| - name: Install stable toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| cache-dependency-path: resx-vscode/package-lock.json | |
| - name: Cache cargo | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Read version metadata | |
| id: version | |
| shell: powershell | |
| run: | | |
| $cargo = Get-Content resx/Cargo.toml -Raw | |
| $extension = Get-Content resx-vscode/package.json -Raw | ConvertFrom-Json | |
| if ($cargo -notmatch 'version\s*=\s*"([^"]+)"') { | |
| throw 'Unable to read version from resx/Cargo.toml' | |
| } | |
| $version = $matches[1] | |
| $extensionVersion = [string]$extension.version | |
| if ($extensionVersion -ne $version) { | |
| throw "Version mismatch: resx/Cargo.toml=$version, resx-vscode/package.json=$extensionVersion" | |
| } | |
| $shortSha = "${{ github.event.workflow_run.head_sha || github.sha }}".Substring(0, 7) | |
| $tag = "v$version" | |
| $releaseName = "resx v$version" | |
| $artifactName = "resx-$version-windows-x86_64" | |
| $publishRoot = "publish" | |
| $publishDir = Join-Path $publishRoot "resx-$version-publish" | |
| $vsixName = "resx-vscode-$version.vsix" | |
| "version=$version" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "extension_version=$extensionVersion" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "short_sha=$shortSha" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "tag=$tag" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "release_name=$releaseName" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "artifact_name=$artifactName" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "publish_root=$publishRoot" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "publish_dir=$publishDir" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| "vsix_name=$vsixName" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| - name: Check release state | |
| id: release_state | |
| shell: powershell | |
| run: | | |
| git fetch --force --tags origin | |
| $tagRef = "refs/tags/${{ steps.version.outputs.tag }}" | |
| $remoteTag = git ls-remote --tags origin $tagRef | |
| if ([string]::IsNullOrWhiteSpace($remoteTag)) { | |
| "tag_exists=false" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| exit 0 | |
| } | |
| $targetSha = "${{ github.event.workflow_run.head_sha || github.sha }}" | |
| $resolvedTagSha = git rev-list -n 1 "${{ steps.version.outputs.tag }}" | |
| if ($resolvedTagSha -ne $targetSha) { | |
| throw "Version tag ${{ steps.version.outputs.tag }} already exists on commit $resolvedTagSha, but this run targets $targetSha. Bump resx/Cargo.toml version before publishing again." | |
| } | |
| "tag_exists=true" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| - name: Materialize signing certificate | |
| id: signing | |
| shell: powershell | |
| run: | | |
| $pfxPath = Join-Path $env:RUNNER_TEMP "resx-signing.pfx" | |
| [IO.File]::WriteAllBytes($pfxPath, [Convert]::FromBase64String("${{ secrets.RESX_SIGNING_PFX_BASE64 }}")) | |
| "pfx_path=$pfxPath" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| - name: Build signed CLI and VSIX | |
| shell: powershell | |
| run: | | |
| ./build.ps1 ` | |
| -Configuration release ` | |
| -OutputRoot "${{ steps.version.outputs.publish_root }}" ` | |
| -PfxPath "${{ steps.signing.outputs.pfx_path }}" ` | |
| -PfxPassword "${{ secrets.RESX_PFX_PASSWORD }}" | |
| - name: Upload workflow artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: resx-release-${{ steps.version.outputs.version }} | |
| path: | | |
| ${{ steps.version.outputs.publish_root }}/*.zip | |
| ${{ steps.version.outputs.publish_root }}/*.sha256 | |
| ${{ steps.version.outputs.publish_dir }}/cli/** | |
| ${{ steps.version.outputs.publish_dir }}/vscode/** | |
| - name: Create version tag | |
| if: steps.release_state.outputs.tag_exists != 'true' | |
| shell: powershell | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag "${{ steps.version.outputs.tag }}" "${{ github.event.workflow_run.head_sha || github.sha }}" | |
| git push origin "refs/tags/${{ steps.version.outputs.tag }}" | |
| - name: Publish VS Code extension | |
| shell: powershell | |
| working-directory: resx-vscode | |
| env: | |
| VSCE_PAT: ${{ secrets.VSCE_PAT }} | |
| run: | | |
| npx --yes @vscode/vsce publish --packagePath "..\${{ steps.version.outputs.publish_dir }}\vscode\${{ steps.version.outputs.vsix_name }}" | |
| - name: Publish GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.version.outputs.tag }} | |
| name: ${{ steps.version.outputs.release_name }} | |
| target_commitish: ${{ github.event.workflow_run.head_sha || github.sha }} | |
| files: | | |
| ${{ steps.version.outputs.publish_root }}/*.zip | |
| ${{ steps.version.outputs.publish_root }}/*.sha256 | |
| ${{ steps.version.outputs.publish_dir }}/vscode/${{ steps.version.outputs.vsix_name }} | |
| ${{ steps.version.outputs.publish_dir }}/vscode/${{ steps.version.outputs.vsix_name }}.sha256 | |
| generate_release_notes: true | |
| overwrite_files: true | |
| append_body: false | |
| prerelease: false | |
| body: | | |
| Release metadata: | |
| - Cargo version: `${{ steps.version.outputs.version }}` | |
| - Commit: `${{ steps.version.outputs.short_sha }}` |