-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (59 loc) · 1.86 KB
/
CD.yml
File metadata and controls
63 lines (59 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: CD
on:
release:
types: [released, prereleased]
workflow_dispatch:
permissions:
contents: read
jobs:
check-tag:
name: Check release tag
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
runs-on: ubuntu-latest
outputs:
should-publish: ${{ github.event_name == 'workflow_dispatch' || steps.check.outputs.match == 'true' }}
steps:
- name: Match semver tag
id: check
if: github.event_name == 'release'
run: |
TAG="${{ github.event.release.tag_name }}"
if [[ "$TAG" =~ ^git-metadata-v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
echo "match=true" >> "$GITHUB_OUTPUT"
else
echo "match=false" >> "$GITHUB_OUTPUT"
fi
release:
name: Release
needs: check-tag
if: needs.check-tag.outputs.should-publish == 'true'
runs-on: ubuntu-latest
permissions:
# Used to sign the release artifacts
id-token: write
# Used to upload release artifacts
contents: write
# Used to generate artifact attestation
attestations: write
steps:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: true
toolchain: stable
- name: Package crates
run: cargo package --workspace
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-path: "target/package/*.crate"
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
IS_PRERELEASE: ${{ github.event.release.prerelease }}
run: |
if [ "$IS_PRERELEASE" = "true" ]; then
cargo publish --workspace --dry-run
else
cargo publish --workspace --token "$CARGO_REGISTRY_TOKEN"
fi