From 8861a54fc7e5b83aac8ba4b98465a303de186b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Sun, 21 Apr 2024 19:57:27 +0200 Subject: [PATCH] ci: add release workflow --- .github/workflows/ci.yml | 2 + .github/workflows/release.yml | 103 ++++++++++++++++++++++++++++++++++ ci/get-release-version.sh | 32 +++++++++++ ci/publish-crates.sh | 28 +++++++++ 4 files changed, 165 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100755 ci/get-release-version.sh create mode 100755 ci/publish-crates.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c3bc80..b848f2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,8 @@ name: CI on: push: + branches: + - '*' pull_request: jobs: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7b85e2b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,103 @@ +name: Release + +on: + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+ + +jobs: + get-version: + runs-on: ubuntu-22.04 + outputs: + version: ${{ steps.get-version.outputs.version }} + steps: + - uses: actions/checkout@v4 + - id: get-version + run: ./ci/get-release-version.sh + + get-ci-artifacts: + runs-on: ubuntu-22.04 + steps: + - name: Download artifacts + uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe + with: + workflow: ci.yml + workflow_conclusion: success + commit: ${{ github.sha }} + event: push + - name: Upload version-changelog artifact + uses: actions/upload-artifact@v4 + with: + name: version-changelog + path: version-changelog/* + if-no-files-found: error + - name: Upload packaged-crates artifact + uses: actions/upload-artifact@v4 + with: + name: packaged-crates + path: packaged-crates/* + if-no-files-found: error + - name: Upload dist-linux artifact + uses: actions/upload-artifact@v4 + with: + name: dist-linux + path: dist-linux/* + if-no-files-found: error + - name: Upload dist-windows artifact + uses: actions/upload-artifact@v4 + with: + name: dist-windows + path: dist-windows/* + if-no-files-found: error + + create-gh-release: + needs: + - get-version + - get-ci-artifacts + permissions: + contents: write + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Download version-changelog artifact + uses: actions/download-artifact@v4 + with: + name: version-changelog + - name: Download packaged-crates artifact + uses: actions/download-artifact@v4 + with: + name: packaged-crates + - name: Download dist-linux artifact + uses: actions/download-artifact@v4 + with: + name: dist-linux + - name: Download dist-windows artifact + uses: actions/download-artifact@v4 + with: + name: dist-windows + - name: Create GitHub release + env: + GH_TOKEN: ${{ github.token }} + RELEASE_VERSION: ${{ needs.get-version.outputs.version }} + run: | + gh release create "${GITHUB_REF#refs/tags/}" \ + "rsjsonnet-lang-$RELEASE_VERSION.crate" \ + "rsjsonnet-front-$RELEASE_VERSION.crate" \ + "rsjsonnet-$RELEASE_VERSION.crate" \ + "rsjsonnet-linux-x86_64.tar.gz" \ + "rsjsonnet-linux-i686.tar.gz" \ + "rsjsonnet-windows-x86_64.zip" \ + "rsjsonnet-windows-i686.zip" \ + --verify-tag \ + --title "$RELEASE_VERSION" \ + --notes-file version-changelog + + publish-crates: + needs: create-gh-release + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - name: Publish + env: + CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }} + run: ./ci/publish-crates.sh diff --git a/ci/get-release-version.sh b/ci/get-release-version.sh new file mode 100755 index 0000000..2295b0b --- /dev/null +++ b/ci/get-release-version.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +. ci/utils.sh + +begin_group "Install Rust" +./ci/install-rust.sh stable.txt --profile minimal -c clippy +# shellcheck disable=SC1091 +. "$HOME/.cargo/env" +end_group + +begin_group "Get release version" + +if [[ "$GITHUB_REF" != "refs/tags/v"* ]]; then + echo "Invalid ref: $GITHUB_REF" + exit 1 +fi + +tag_version="${GITHUB_REF#refs/tags/v}" +echo "Tag version: $tag_version" + +crate="rsjsonnet" +crate_version="$(crate_version "$crate")" +echo "Crate version: $crate_version" + +if [ "$tag_version" != "$crate_version" ]; then + echo "Tag version does not match crate version" + exit 1 +fi + +echo "version=$tag_version" >> "$GITHUB_OUTPUT" +end_group diff --git a/ci/publish-crates.sh b/ci/publish-crates.sh new file mode 100755 index 0000000..5260e85 --- /dev/null +++ b/ci/publish-crates.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +. ci/utils.sh + +begin_group "Install Rust" +./ci/install-rust.sh stable.txt --profile minimal -c clippy +# shellcheck disable=SC1091 +. "$HOME/.cargo/env" +end_group + +begin_group "Fetch dependencies" +cargo fetch --locked +end_group + +export CARGO_REGISTRY_TOKEN="$CRATES_IO_TOKEN" + +crates=( + rsjsonnet-lang + rsjsonnet-front + rsjsonnet +) + +for crate in "${crates[@]}"; do + begin_group "Publish $crate" + cargo publish -p "$crate" --no-verify --locked + end_group +done