-
Notifications
You must be signed in to change notification settings - Fork 17
137 lines (123 loc) · 4.42 KB
/
ci.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Rust
on:
push:
branches: [ 0.7.x ]
pull_request:
branches: [ 0.7.x ]
env:
CARGO_TERM_COLOR: always
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run check
run: cargo check
rustfmt:
name: rustfmt
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: rustfmt
- name: Check formatting
run: |
cargo fmt -- --check
rustclippy:
name: rustclippy
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: clippy
- name: Clippy check
run: |
cargo clippy
test:
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
profile: minimal
components: clippy
- name: Run tests
run: |
cargo test
publish:
runs-on: ubuntu-20.04
needs: [rustfmt, rustclippy]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/0.7.x'
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
# fetch tags for cargo ws publish
# might be a simple `fetch-tags: true` option soon, see https://github.com/actions/checkout/pull/579
fetch-depth: 0
- name: Setup
run: |
git config user.name github-actions
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
cargo install --git https://github.com/miraclx/cargo-workspaces --rev b2d49b9e575e29fd2395352e4d0df47def025039 cargo-workspaces
export GIT_PREVIOUS_TAG=$(git describe --tags --abbrev=0)
echo "GIT_PREVIOUS_TAG=${GIT_PREVIOUS_TAG}" >> $GITHUB_ENV
echo "[ pre run] current latest git tag is \"${GIT_PREVIOUS_TAG}\""
- name: Publish to crates.io and tag the commit
id: tag-and-publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo ws publish --all --yes --exact \
--skip-published --no-git-commit --allow-dirty \
--tag-existing --tag-prefix 'v' \
--tag-msg 'crates.io snapshot' --tag-msg '%{https://crates.io/crates/%n/%v}' \
--no-individual-tags --no-git-push
export GIT_LATEST_TAG=$(git describe --tags --abbrev=0)
echo "GIT_LATEST_TAG=${GIT_LATEST_TAG}" >> $GITHUB_ENV
echo "[post run] current latest git tag is \"${GIT_LATEST_TAG}\""
echo "::set-output name=tagged::$( [[ "$GIT_LATEST_TAG" == "$GIT_PREVIOUS_TAG" ]] && echo 0 || echo 1 )"
# returning multi-line outputs gets truncated to include only the first line
# we have to escape the newline chars, runner auto unescapes them later
# https://github.community/t/set-output-truncates-multiline-strings/16852/3
GIT_TAG_MESSAGE="$(git tag -l --format='%(body)' ${GIT_LATEST_TAG})"
GIT_TAG_MESSAGE="${GIT_TAG_MESSAGE//'%'/'%25'}"
GIT_TAG_MESSAGE="${GIT_TAG_MESSAGE//$'\n'/'%0A'}"
GIT_TAG_MESSAGE="${GIT_TAG_MESSAGE//$'\r'/'%0D'}"
echo "::set-output name=git_tag_message::${GIT_TAG_MESSAGE}"
- name: Push tags to GitHub (if any)
if: steps.tag-and-publish.outputs.tagged == 1
run: git push --tags
- name: Extract release notes
if: steps.tag-and-publish.outputs.tagged == 1
id: extract-release-notes
uses: ffurrer2/extract-release-notes@c24866884b7a0d2fd2095be2e406b6f260479da8
- name: Create release
if: steps.tag-and-publish.outputs.tagged == 1
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.GIT_LATEST_TAG }}
release_name: ${{ env.GIT_LATEST_TAG }}
body: |
## What's changed?
${{ steps.extract-release-notes.outputs.release_notes }}
**Crate Link**: ${{ steps.tag-and-publish.outputs.git_tag_message }}
**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ env.GIT_PREVIOUS_TAG }}...${{ env.GIT_LATEST_TAG }}