|
| 1 | +name: release |
| 2 | +on: |
| 3 | + workflow_run: |
| 4 | + workflows: [build] |
| 5 | + branches: [main] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + workflow_dispatch: |
| 9 | + branches: [main] |
| 10 | + |
| 11 | +jobs: |
| 12 | + tag-release: |
| 13 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} || ${{ github.event.workflow_dispatch }} |
| 14 | + name: tag-release (ubuntu-latest) |
| 15 | + runs-on: ubuntu-latest |
| 16 | + outputs: |
| 17 | + upload_url: ${{ steps.create-release.outputs.upload_url }} |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout repository |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 2 |
| 24 | + - name: Set up Rust |
| 25 | + run: rustup toolchain add --profile minimal stable --component clippy,rustfmt |
| 26 | + |
| 27 | + # Cargo setup |
| 28 | + - name: Set up Cargo cache |
| 29 | + uses: actions/cache@v4 |
| 30 | + with: |
| 31 | + path: | |
| 32 | + ~/.cargo/registry |
| 33 | + ~/.cargo/git |
| 34 | + target |
| 35 | + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} |
| 36 | + |
| 37 | + # Tag the commit with the library version |
| 38 | + - name: Create git tag |
| 39 | + uses: salsify/action-detect-and-tag-new-version@v2 |
| 40 | + with: |
| 41 | + version-command: scripts/get_version.sh |
| 42 | + |
| 43 | + # Set release output variables |
| 44 | + - name: Set output |
| 45 | + id: vars |
| 46 | + run: | |
| 47 | + echo "TAG_NAME=v$(scripts/get_version.sh)" >> $GITHUB_ENV |
| 48 | + echo "RELEASE_NAME=$(scripts/get_version.sh)" >> $GITHUB_ENV |
| 49 | + echo "## Release notes" > NOTES.md |
| 50 | + sed -n '/^## /{n; :a; /^## /q; p; n; ba}' CHANGELOG.md >> NOTES.md |
| 51 | + # Create GitHub release |
| 52 | + - name: Create release |
| 53 | + id: create-release |
| 54 | + uses: softprops/action-gh-release@v1 |
| 55 | + with: |
| 56 | + name: ${{ env.RELEASE_NAME }} |
| 57 | + tag_name: ${{ env.TAG_NAME }} |
| 58 | + append_body: true |
| 59 | + body_path: ./NOTES.md |
| 60 | + prerelease: false |
| 61 | + |
| 62 | + - name: Remove notes |
| 63 | + # Force to not error if it doesn't exist |
| 64 | + run: rm --force NOTES.md |
| 65 | + |
| 66 | + - name: Publish to crates.io |
| 67 | + run: cargo publish --token ${CARGO_REGISTRY_TOKEN} |
| 68 | + env: |
| 69 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
0 commit comments