Skip to content

Commit

Permalink
ci: add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosm committed Apr 21, 2024
1 parent 72f6774 commit 8861a54
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: CI

on:
push:
branches:
- '*'
pull_request:

jobs:
Expand Down
103 changes: 103 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions ci/get-release-version.sh
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions ci/publish-crates.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8861a54

Please sign in to comment.