Skip to content

Commit

Permalink
feat: release script
Browse files Browse the repository at this point in the history
  • Loading branch information
EstebanBorai authored Jul 25, 2023
1 parent 0734398 commit e4cd04e
Showing 1 changed file with 53 additions and 24 deletions.
77 changes: 53 additions & 24 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
name: release

on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
type: choice
required: true
description: 'Version number to bump'
options:
- patch
- minor
- major

permissions:
contents: write
issues: write
pull-requests: write

jobs:
publish-dry-run:
Expand All @@ -20,38 +32,55 @@ jobs:
- name: publish crate
run: cargo publish --dry-run

create-release:
release:
name: Create Release
needs: publish-dry-run
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Create Release with Notes
uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
await github.request(`POST /repos/${{ github.repository }}/releases`, {
tag_name: "${{ github.ref }}",
generate_release_notes: true
});
publish-crate:
name: Publish to crates.io
needs: create-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- uses: actions-rs/toolchain@v1
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- run: cargo login ${CRATES_IO_TOKEN}
override: true

- name: Install `cargo-edit`
run: cargo install cargo-edit

- id: cargo-set-version
name: Set Version
run: cargo set-version --bump ${{ inputs.version }}

- name: Set Crate Version as Environment Variable
run: |
CARGO_TOML_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/[\"]/, "", $2); printf("%s",$2) }' Cargo.toml)
echo "CRATE_VERSION=$CARGO_TOML_VERSION" >> $GITHUB_ENV
- name: Create Commit
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "chore: bump version to v$CRATE_VERSION"
git push origin main --follow-tags
- name: Login to Crates.io
run: cargo login ${CRATES_IO_TOKEN}
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}

- name: publish crate
- name: Publish crate
run: cargo publish

- name: Create Release
id: create_release
uses: actions/github-script@v5
with:
script: |
await github.request(`POST /repos/${{ github.repository }}/releases`, {
tag_name: "v${{ env.CRATE_VERSION }}",
generate_release_notes: true
});

0 comments on commit e4cd04e

Please sign in to comment.