Skip to content

Commit

Permalink
ci: crate release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Jul 3, 2023
1 parent 0a37a27 commit 28483f5
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
on:
push:
tags:
- "starknet/v*.*.*"
- "starknet-*/v*.*.*"

name: "Release"

jobs:
# Just in case we accidentally release something not on master.
commit-branch-check:
name: "Check commit branch"
runs-on: "ubuntu-latest"

steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"
with:
fetch-depth: 0

- name: "Check if commit is on master"
run: |
COMMIT_HASH=$(git log -1 --format=%H ${{ github.ref }})
GREP_OUTPUT=$(git log origin/master --format=%H | grep "$COMMIT_HASH")
if [ -z "$GREP_OUTPUT" ]; then
echo "Cannot release commits not on the master branch"
exit 1
fi
crate-version-check:
name: "Check crate version"
runs-on: "ubuntu-latest"
needs: ["commit-branch-check"]

steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"

- name: "Derive crate info from Git tag"
run: |
FULL_REF="${{ github.ref }}"
REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$"
[[ $FULL_REF =~ $REGEX ]];
echo "CRATE=${BASH_REMATCH[1]}" >> $GITHUB_ENV
echo "VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV
- name: "Check against Cargo.toml"
run: |
if [ "starknet" != "$CRATE" ]; then
cd $CRATE
fi
GREP_OUTPUT=$(cat Cargo.toml | grep "^version = \"${VERSION}\"$")
if [ -z "$GREP_OUTPUT" ]; then
echo "Crate version mismatch"
exit 1
fi
build:
name: "Build for ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
needs: ["crate-version-check"]

strategy:
matrix:
os:
- "ubuntu-latest"
- "windows-latest"
- "macos-latest"

steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"

- name: "Setup stable toolchain"
uses: "actions-rs/toolchain@v1"
with:
toolchain: "stable"
profile: "minimal"
override: true

- name: "Derive crate info from Git tag"
run: |
FULL_REF="${{ github.ref }}"
REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$"
[[ $FULL_REF =~ $REGEX ]];
echo "CRATE=${BASH_REMATCH[1]}" >> $GITHUB_ENV
echo "VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV
- name: "Build crate"
run: |
cargo build --package $CRATE --all-targets
crates-io-release:
name: "Release to crates.io"
runs-on: "ubuntu-latest"

# We don't want to publish something that wouldn't even build to crates.io
needs: ["build"]

steps:
- name: "Checkout source code"
uses: "actions/checkout@v3"

- name: "Derive crate info from Git tag"
run: |
FULL_REF="${{ github.ref }}"
REGEX="^refs\/tags\/([a-z\\-]*)\/v(.*)$"
[[ $FULL_REF =~ $REGEX ]];
echo "CRATE=${BASH_REMATCH[1]}" >> $GITHUB_ENV
echo "VERSION=${BASH_REMATCH[2]}" >> $GITHUB_ENV
- name: "Login to crates.io"
run: |
cargo login ${{ secrets.CRATES_IO_API_TOKEN }}
- name: "Public crate"
run: |
cargo publish --package $CRATE

0 comments on commit 28483f5

Please sign in to comment.