diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6bc24a8 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,125 @@ +name: Release + +on: + push: + tags: + - "v*" + - "[0-9]*" + workflow_dispatch: + +permissions: + contents: write + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + name: Build ${{ matrix.target }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - target: windows-x64 + os: windows-latest + script-target: win + - target: linux-x64 + os: ubuntu-latest + script-target: linux-x64 + - target: linux-arm64 + os: ubuntu-latest + script-target: linux-arm64 + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Resolve version + shell: pwsh + run: | + if ($env:GITHUB_REF_TYPE -eq "tag") { + $version = $env:GITHUB_REF_NAME -replace '^v', '' + } else { + $cargoToml = Get-Content -Raw -Path "Cargo.toml" + if ($cargoToml -notmatch '(?m)^version\s*=\s*"([^"]+)"') { + throw "Cannot read package version from Cargo.toml" + } + $version = $Matches[1] + } + "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8 + + - name: Install Windows Rust target + if: runner.os == 'Windows' + shell: pwsh + run: rustup target add x86_64-pc-windows-msvc + + - name: Set up QEMU + if: runner.os == 'Linux' + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + if: runner.os == 'Linux' + uses: docker/setup-buildx-action@v3 + + - name: Build release binary + shell: pwsh + run: ./scripts/publish-binaries.ps1 -Version "${env:VERSION}" -Target "${{ matrix.script-target }}" -Clean + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: cdxs-${{ matrix.target }} + path: dist/* + if-no-files-found: error + + release: + name: Publish GitHub Release + needs: build + runs-on: ubuntu-latest + if: github.ref_type == 'tag' + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + path: dist + merge-multiple: true + + - name: Generate changelog + shell: bash + run: | + current_tag="${GITHUB_REF_NAME}" + previous_tag="$(git describe --tags --abbrev=0 "${current_tag}^{}^" 2>/dev/null || true)" + + { + echo "## Changes" + echo + if [[ -n "${previous_tag}" ]]; then + echo "Changes since \`${previous_tag}\`:" + echo + git log --no-merges --pretty=format:'- %s (%h)' "${previous_tag}..${current_tag}" + else + echo "Initial release changes:" + echo + git log --no-merges --pretty=format:'- %s (%h)' "${current_tag}^{}" + fi + echo + echo + echo "## Artifacts" + echo + echo "- \`cdxs-${current_tag#v}-windows-x64.exe\`" + echo "- \`cdxs-${current_tag#v}-linux-x64\`" + echo "- \`cdxs-${current_tag#v}-linux-arm64\`" + } > RELEASE_NOTES.md + + - name: Publish release + uses: softprops/action-gh-release@v2 + with: + files: dist/* + body_path: RELEASE_NOTES.md