Skip to content

Commit

Permalink
feat(ci): Create publish.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekMasher committed Jun 20, 2024
1 parent 40f9d0e commit a3b0ecb
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Cargo - Publish

on:
push:
branches: [ main ]

jobs:
cargo-check:
runs-on: ubuntu-latest

outputs:
version: ${{ steps.crates-check.outputs.version }}
outdated: ${{ steps.crates-check.outputs.outdated }}

steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Check crates.io"
id: crates-check
run: |
set -e
CARGO_LOCATION="./Cargo.toml"
CRATE_NAME="ghastoolkit"
# TODO: Auto detect name
current_version=$(grep -oP '^version = "(.*)"$' $CARGO_LOCATION | cut -d '"' -f 2)
crates_remote=$(curl -s https://crates.io/api/v1/crates/$CRATE_NAME/versions | jq -r '.versions[0].num')
echo "💻 Current version :: $current_version"
echo "🦀 Crates.io version :: $crates_remote"
if [ "$current_version" != "$crates_remote" ]; then
echo "🚀 The crate is outdated... Let's update it!"
echo "version=$current_version" >> $GITHUB_OUTPUT
echo "outdated=true" >> $GITHUB_OUTPUT
else
echo "🍹 Crate is up to date. Lets sit back and relax..."
echo "outdated=false" >> $GITHUB_OUTPUT
fi
cargo-publish:
runs-on: ubuntu-latest
needs: [ cargo-check ]

if: ${{ needs.cargo-check.outputs.outdated == 'true' }}

permissions:
contents: write

steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Setup - Rust Toolchain"
uses: dtolnay/rust-toolchain@nightly
with:
components: clippy

- name: "Build / Validate"
run: |
cargo build --workspace
cargo test --workspace
- name: "Publish"
run: |
set -e
cargo login ${{ secrets.CRATES_TOKEN }}
INPUT="ghastoolkit,ghastoolkit-cli"
IFS=',' read -r -a elements <<< "$INPUT"
for element in "${elements[@]}"
do
echo "🚀 Publishing crate '$element'"
cargo publish -p "$element" --allow-dirty
done
- name: "GitHub Release"
env:
GH_TOKEN: ${{ github.token }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git tag "${{ needs.cargo-check.outputs.version }}" --force
git push origin ${{ github.ref_name }}
git push origin --tags --force
gh release create --latest --generate-notes \
--title "v${{ needs.cargo-check.outputs.version }}" \
"${{ needs.cargo-check.outputs.version }}"

0 comments on commit a3b0ecb

Please sign in to comment.