-
Notifications
You must be signed in to change notification settings - Fork 1
48 lines (43 loc) · 1.54 KB
/
publish.yml
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
name: Publish Crate
on:
push:
branches:
- master
paths:
- Cargo.toml
repository_dispatch:
types: publish
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set variables
id: vars
run: |
NAME=$(cargo metadata -q --no-deps | jq -r '.packages[0].name')
VERSION=$(cargo metadata -q --no-deps | jq -r '.packages[0].version')
echo "::set-output name=name::$NAME"
echo "::set-output name=version::v$VERSION"
echo "Found $NAME-$VERSION"
- name: Lookup ${{ steps.vars.outputs.version }} tag
id: need-release
uses: actions/github-script@v3
with:
script: |
const version = '${{ steps.vars.outputs.version }}'
const tags = await github.repos.listTags(context.repo)
if (tags.data.some(tag => tag.name == version)) {
core.info(`Found ${version} tag -- will proceed with publishing`)
return true
}
core.info(`Found no ${version} tag -- will skip publish step`)
return false
# The result from above is JSON-encoded, meaning that we
# end up with the string 'true', not the Boolean true.
- if: steps.need-release.outputs.result == 'true'
name: Publish crate to crates.io
run: |
echo "Publishing ${{ steps.vars.outputs.name }}-${{ steps.vars.outputs.version }}"
cargo publish --token ${{ secrets.CARGO_TOKEN }}