Skip to content

Commit

Permalink
wip: 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 79a2456
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 6 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
81 changes: 81 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Release

on:
push:
tags:
#- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-test-release

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

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: 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" \
--prerelease \
--verify-tag \
--title "$RELEASE_VERSION" \
--notes-file version-changelog
publish-crate:
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-crate.sh
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## 0.1.1 (unreleased)
## 0.1.1 (9999-99-99)

### Changed

Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ members = [
resolver = "2"

[workspace.package]
version = "0.1.1-pre"
version = "0.1.1"
authors = ["Eduardo Sánchez Muñoz <[email protected]>"]
edition = "2021"
rust-version = "1.74"
repository = "https://github.com/eduardosm/rsjsonnet"
license = "MIT OR Apache-2.0"
publish = false
publish = true

[workspace.dependencies]
rsjsonnet-front = { path = "rsjsonnet-front", version = "0.1.1-pre" }
Expand Down
33 changes: 33 additions & 0 deletions ci/get-release-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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}"
tag_version="${tag_version%-test-release}"
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
29 changes: 29 additions & 0 deletions ci/publish-crates.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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 --dry-run
end_group
exit 0
done

0 comments on commit 79a2456

Please sign in to comment.