-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (83 loc) · 2.94 KB
/
tag-release-and-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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Tag, Release and Publish
on:
push:
branches: ["main"]
permissions:
contents: write
jobs:
tag:
runs-on: ubuntu-latest
outputs:
tag_created: ${{ steps.create_tag.outputs.tag_created }}
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get latest tag
id: get_latest_tag
run: |
LATEST_TAG=$(git describe --tags --abbrev=0)
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Get the current version
id: get_version
run: |
VERSION=v$(cat Cargo.toml | grep -m 1 version | grep -o -P "\d+\.\d+\.\d+")
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Create tag
if: ${{env.VERSION != env.LATEST_TAG}}
id: create_tag
run: |
git tag ${{env.VERSION}}
git push origin ${{env.VERSION}}
echo "tag_created=true" >> $GITHUB_OUTPUT
release:
needs: tag
if: needs.tag.outputs.tag_created == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get the current version
id: get_version
run: |
VERSION=$(cat Cargo.toml | grep version | grep -o -P "\d+\.\d+\.\d+")
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Get Changelog line
run: |
CHANGELOG_HEADER=$(cat CHANGELOG.md | grep "\[${{env.VERSION}}\]" | sed s/#//g | sed -E "s/\(.*\)//g" | sed "s/\ \[//g" | sed "s/\]//g" | sed "s/\ /-/g" | sed "s/\.//g")
echo "CHANGELOG_HEADER=$CHANGELOG_HEADER" >> $GITHUB_ENV
- name: Debug Info
run: |
echo "Version: ${{ env.VERSION }}"
echo "Changelog Header: ${{ env.CHANGELOG_HEADER }}"
- name: Check If Changelog Header is valid
if: ${{ env.CHANGELOG_HEADER == '' }}
run: exit 1
- name: Create GitHub Release
if: ${{ env.CHANGELOG_HEADER != '' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.VERSION }}
release_name: v${{ env.VERSION }}
draft: false
body: See changelog for this version [here](CHANGELOG.md#${{env.CHANGELOG_HEADER}})
prerelease: false
publish:
needs: [tag,release]
if: needs.tag.outputs.tag_created == 'true'
# Based on: https://users.rust-lang.org/t/does-anyone-use-github-actions-to-run-cargo-publish/92374/5
name: Publish to crates.io
runs-on: ubuntu-latest
environment: crates.io
steps:
- uses: actions/checkout@v3
- uses: swatinem/rust-cache@v2
- name: cargo publish
# https://doc.rust-lang.org/cargo/reference/config.html?highlight=CARGO_REGISTRY_TOKEN#credentials
run: |
cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }} && cargo publish --verbose --locked