Skip to content

Commit 48cd240

Browse files
authored
Merge pull request #24 from mkantor/ci++
Improved CI and automated release workflow.
2 parents ec402a5 + 71fd0ff commit 48cd240

File tree

3 files changed

+120
-3
lines changed

3 files changed

+120
-3
lines changed

.github/workflows/release.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+'
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
13+
verify-version:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- run: |
18+
tag="${GITHUB_REF#refs/tags/}"
19+
package_version="$(cargo read-manifest | jq --raw-output .version)"
20+
echo "Git tag name: ${tag}"
21+
echo "Cargo.toml version: ${package_version}"
22+
test "$tag" == "$package_version"
23+
24+
# Run the tests and create a fresh cache before releasing. Make sure that the
25+
# same code that was tested is what gets released.
26+
test:
27+
runs-on: ${{ matrix.os }}
28+
strategy:
29+
matrix:
30+
os:
31+
- ubuntu-latest
32+
- macos-latest
33+
steps:
34+
- uses: actions/checkout@v2
35+
- uses: actions/cache@v2
36+
with:
37+
path: |
38+
~/.cargo/registry
39+
~/.cargo/git
40+
target
41+
key: ${{ runner.os }}-cargo-${{ github.job }}-${{ secrets.CI_CACHE_VERSION }}
42+
- run: cargo test
43+
44+
publish-binary:
45+
needs:
46+
- verify-version
47+
- test
48+
runs-on: ${{ matrix.os }}
49+
strategy:
50+
matrix:
51+
os:
52+
- ubuntu-latest
53+
- macos-latest
54+
include:
55+
- os: macos-latest
56+
artifact_prefix: macos
57+
target: x86_64-apple-darwin
58+
- os: ubuntu-latest
59+
artifact_prefix: linux
60+
target: x86_64-unknown-linux-gnu
61+
steps:
62+
- uses: actions/checkout@v2
63+
- uses: actions/cache@v2
64+
with:
65+
path: |
66+
~/.cargo/registry
67+
~/.cargo/git
68+
target
69+
key: ${{ runner.os }}-cargo-${{ github.job }}-${{ secrets.CI_CACHE_VERSION }}
70+
- run: cargo build --release --target ${{ matrix.target }}
71+
- name: package binary
72+
shell: bash
73+
run: |
74+
cd target/${{ matrix.target }}/release
75+
strip ${{ github.event.repository.name }}
76+
tar czvf \
77+
${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.tar.gz \
78+
${{ github.event.repository.name }}
79+
shasum -a 256 ${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.tar.gz \
80+
> ${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.sha256
81+
- name: publish release to github
82+
uses: softprops/action-gh-release@v1
83+
with:
84+
files: |
85+
target/${{ matrix.target }}/release/${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.tar.gz
86+
target/${{ matrix.target }}/release/${{ github.event.repository.name }}-${{ matrix.artifact_prefix }}.sha256
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89+
90+
publish-crate:
91+
needs:
92+
- verify-version
93+
- test
94+
runs-on: ubuntu-latest
95+
steps:
96+
- uses: actions/checkout@v2
97+
- uses: actions/cache@v2
98+
with:
99+
path: |
100+
~/.cargo/registry
101+
~/.cargo/git
102+
target
103+
key: ${{ runner.os }}-cargo-${{ github.job }}-${{ secrets.CI_CACHE_VERSION }}
104+
- run: cargo publish --token ${{ secrets.CARGO_API_TOKEN }} --allow-dirty

.github/workflows/validate-commit.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ env:
88
jobs:
99

1010
test:
11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
- macos-latest
1217
steps:
1318
- uses: actions/checkout@v2
1419
- uses: actions/cache@v2
@@ -17,8 +22,15 @@ jobs:
1722
~/.cargo/registry
1823
~/.cargo/git
1924
target
20-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
25+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ secrets.CI_CACHE_VERSION }}
2126
- run: cargo test
27+
# There is a bug with BSD tar on macOS where the first 8MB of the file are
28+
# sometimes all NUL bytes. See https://github.com/actions/cache/issues/403
29+
# and https://github.com/rust-lang/cargo/issues/8603 for some more
30+
# information. An alternative solution here is to install GNU tar, but
31+
# flushing the disk cache seems to work, too.
32+
- run: sudo purge
33+
if: startsWith(matrix.os, 'macos-')
2234

2335
lint:
2436
runs-on: ubuntu-latest
@@ -30,7 +42,7 @@ jobs:
3042
~/.cargo/registry
3143
~/.cargo/git
3244
target
33-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
45+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ secrets.CI_CACHE_VERSION }}
3446
- run: cargo clippy -- -D warnings
3547

3648
format:

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.0.1"
44
authors = ["Matt Kantor <[email protected]>"]
55
description = "A web server for static and dynamic content"
66
repository = "https://github.com/mkantor/operator"
7+
readme = "README.md"
78
license = "GPL-3.0"
89
edition = "2018"
910
exclude = [

0 commit comments

Comments
 (0)