Skip to content

Commit 3739730

Browse files
authored
chore(ci/cd): Add GitHub actions and Makefile like the other repos. (#14)
* chore(ci/cd): Add GitHub actions and Makefile like the other repos. * chore(quality): Run Cargo fmt.
1 parent 222342c commit 3739730

8 files changed

Lines changed: 364 additions & 130 deletions

File tree

.github/actions/setup/action.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This private action setups all the necessary to run on all the workflows.
2+
#
3+
# By default it installs rust considering the input 'rust-toolchain' to choose
4+
# which toolchain to install, then installs all the required rust packages.
5+
#
6+
# If there is an npm package specified then it also installs node along
7+
# the required packages.
8+
9+
name: Setup Environment
10+
11+
inputs:
12+
rust-toolchain:
13+
required: false
14+
default: stable
15+
rust-components:
16+
required: false
17+
default: ""
18+
rust-packages:
19+
required: false
20+
default: ""
21+
npm-packages:
22+
required: false
23+
default: ""
24+
25+
runs:
26+
using: "composite"
27+
steps:
28+
- name: Setup Node
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: "22.18.0"
32+
33+
34+
- name: Configure GIT
35+
shell: bash
36+
run: |
37+
git config user.name "github-actions[bot]"
38+
git config user.email "github-actions[bot]@users.noreply.github.com"
39+
40+
41+
- name: Setup Rust
42+
uses: actions-rust-lang/setup-rust-toolchain@v1
43+
with:
44+
toolchain: ${{ inputs.rust-toolchain }}
45+
components: ${{ inputs.rust-components }}
46+
47+
48+
- name: Set Rust Bin Environment Variable
49+
shell: bash
50+
run: echo "PATH=$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV
51+
52+
53+
- uses: cargo-bins/cargo-binstall@main
54+
- name: Install Rust Packages
55+
if: ${{ inputs.rust-packages != '' }}
56+
shell: bash
57+
run: cargo binstall --force -y ${{ inputs.rust-packages }}
58+
59+
60+
- name: Install NPM Packages
61+
if: ${{ inputs.npm-packages != '' }}
62+
shell: bash
63+
run: npm install -g ${{ inputs.npm-packages }}

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
- [ ] I've checked existing issues and pull requests
44
- [ ] I've read the [Code of Conduct](../CODE_OF_CONDUCT.md)
5-
- [ ] I've [implemented tests](../TESTING.md) for my changes
5+
- [ ] Are [tests implemented](../TESTING.md) for my changes
66
- [ ] I've listed all my changes in the `Changes` section
77

88
## Changes

.github/workflows/010-tests.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# This workflow decides whether a new version should be published,
2+
# basically by running tests, lints and version checks to ensure
3+
# everything is as it should be.
4+
#
5+
# This will fail in case
6+
# - Any of the past commits don't follow the conventional commits standard.
7+
# - Cargo Clippy reports a broken rule.
8+
# - Cargo Fmt reports a broken rule.
9+
# - Tests fail
10+
# - Code coverage reports < 80% coverage.
11+
#
12+
# For now this only runs on main and on linux, since this is a library,
13+
# once further standards are enforced this might change.
14+
15+
name: tests
16+
17+
on:
18+
push:
19+
branches: [main]
20+
pull_request:
21+
branches: [main]
22+
23+
jobs:
24+
tests:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
actions: read
28+
29+
steps:
30+
# Need to checkout the repository before
31+
# using composite action to setup.
32+
- name: Checkout Repository
33+
uses: actions/checkout@v4
34+
with:
35+
fetch-depth: 0
36+
37+
38+
# Setup the environment with default
39+
# programs and setup required packages.
40+
- name: Setup Environment
41+
uses: ./.github/actions/setup
42+
with:
43+
rust-toolchain: nightly
44+
rust-components: llvm-tools-preview rustfmt clippy
45+
rust-packages: cargo-llvm-cov
46+
47+
48+
# Validate conventional commits from the
49+
# current branch.
50+
- name: Conventional Commit Validation
51+
uses: webiny/action-conventional-commits@v1.3.0
52+
with:
53+
allowed-commit-types: "feat,fix,docs,test,ci,refactor,perf,chore,revert"
54+
55+
56+
# Run code lints and tests
57+
- name: Run Code Lint Checks And Tests
58+
run: |
59+
make test-code;
60+
make test-format;
61+
make test-clippy;
62+
63+
64+
# Generate code coverage, this only
65+
# happens in main because its the only
66+
# branch we consideer for coverage.
67+
- name: Generate Code Coverage
68+
if: success() && github.ref == 'refs/heads/main'
69+
run: make test-coverage-export;
70+
71+
72+
# Upload the coverage to codecov
73+
# Only main is considered because
74+
# codecov is known to fail on other
75+
# branches due to branch protection
76+
# rules.
77+
- name: Upload coverage to Codecov
78+
uses: codecov/codecov-action@v5
79+
if: success() && github.ref == 'refs/heads/main'
80+
with:
81+
file: coverage.lcov
82+
fail_ci_if_error: true
83+
token: ${{ secrets.CODECOV_TOKEN }}
84+
slug: FlakySL/actix_failwrap
85+
verbose: true
86+
87+
88+
# This is more relevant while merging.
89+
# Since by merge rules we deny failed
90+
# workflows, in the case where coverage is
91+
# below 80% the workflow will fail thus
92+
# The branch won't be able to be merged.
93+
- name: Fail if overall coverage is below 80%
94+
run: |
95+
coverage=$(make test-coverage-get);
96+
coverage=${coverage//[[:space:]};
97+
coverage=${coverage%.*}
98+
if (( coverage < 80 ))
99+
then
100+
echo "❌ Coverage is below 80% ($coverage%)"
101+
exit 1
102+
else
103+
echo "✅ Coverage meets requirement ($coverage%)"
104+
fi

.github/workflows/020-publish.yml

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# This action will keep track of the current crate verision, the last
2+
# pushed git tag and determine whether the project should be deployed
3+
#
4+
# Additionally it will keep track whether THE LAST TAG has a release
5+
# assigned, if it doesn't unless otherwise specified it will attempt
6+
# to create one.
7+
8+
name: publish
9+
10+
on:
11+
workflow_run:
12+
workflows:
13+
- tests
14+
types:
15+
- completed
16+
17+
jobs:
18+
publish:
19+
runs-on: ubuntu-latest
20+
# This only runs on main after tests have concluded successfully.
21+
if: github.ref == 'refs/heads/main' && github.event.workflow_run.conclusion == 'success'
22+
env:
23+
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
24+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
permissions:
26+
contents: write
27+
28+
steps:
29+
# Need to checkout the repository before
30+
# using composite action to setup.
31+
- name: Checkout Repository
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
37+
# Setup the environment with default
38+
# programs and setup required packages.
39+
- name: Setup Environment
40+
uses: ./.github/actions/setup
41+
with:
42+
npm-packages: "semver"
43+
44+
45+
# Parsing all the previous versions
46+
# is essential to determining whether a new
47+
# version should be published.
48+
#
49+
# This exports the crate version and the
50+
# latest git tag which help determine whether
51+
# a new version should be published.
52+
- name: Get And Parse Repository Versions
53+
id: versions
54+
run: |
55+
# The version of the main crate which should be the first on the list in the workspace config.
56+
echo "crate_version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')" \
57+
>> $GITHUB_OUTPUT;
58+
59+
# The last pushed git tag if any.
60+
last_git_tag="$(git describe --tags --abbrev=0 || echo '')";
61+
if [[ -z "$last_git_tag" ]]; then exit 0; fi;
62+
echo "last_tag=$last_git_tag" >> $GITHUB_OUTPUT;
63+
64+
65+
# In the case the last git tag is minor than
66+
# the current crate version, determine that
67+
# a new version should be published to crates.io.
68+
#
69+
# In the case the last git tag doesn't have
70+
# a release associated to it, determine a release
71+
# should be created with git cliff.
72+
- name: Determine What Should Be Done
73+
id: to_do
74+
run: |
75+
crate_version="${{ steps.versions.outputs.crate_version }}";
76+
last_tag="${{ steps.versions.outputs.last_tag }}";
77+
78+
# If there is no last tag, make up 0.0.0.
79+
if [ -z "$last_tag" ]; then
80+
last_tag="0.0.0"
81+
fi
82+
83+
# If the last published tag is minor than the crate's tag
84+
# determine that the crate should be published.
85+
if semver -r "> $last_tag" "$crate_version"; then
86+
echo "should_publish=true" >> $GITHUB_OUTPUT
87+
else
88+
echo "should_publish=false" >> $GITHUB_OUTPUT
89+
fi
90+
91+
# If there is no release associated to the last tag
92+
# determine that a release should be created.
93+
if ! gh release view "$last_tag" >/dev/null 2>&1; then
94+
echo "should_release=true" >> $GITHUB_OUTPUT;
95+
else
96+
echo "should_release=false" >> $GITHUB_OUTPUT;
97+
fi
98+
99+
100+
# In the case it's determined that the crate should be
101+
# published, then we call cargo publish and create
102+
# a new tag for the publication in the case the publication
103+
# succeeded.
104+
- name: Publish And Create A New Tag
105+
id: publish
106+
if: success() && steps.to_do.outputs.should_publish == 'true'
107+
run: |
108+
crate_version="${{ steps.versions.outputs.crate_version }}"
109+
110+
# If cargo publish fails a new release won't be made.
111+
# Make sure that it exits in case github actions doesn't halt.
112+
cargo publish || exit 1;
113+
114+
git tag "$crate_version";
115+
git push origin "$crate_version";
116+
117+
# We make a version override for which the changelog
118+
# will be created instead.
119+
echo "version_override=$crate_version" >> $GITHUB_OUTPUT;
120+
121+
122+
# In the case that or either it's determined that
123+
# a release should be created or a new publication
124+
# is done, then we call git-cliff-action@v4 to process
125+
# creating a changelog.
126+
- name: Generate a changelog
127+
uses: orhun/git-cliff-action@v4
128+
if: >
129+
success() && (
130+
steps.to_do.outputs.should_release == 'true' ||
131+
steps.publish.outputs.version_override != ''
132+
)
133+
id: git-cliff
134+
with:
135+
config: cliff.toml
136+
args: --verbose --latest --strip header
137+
138+
139+
# We call create-release@v1 in the case the same
140+
# condition as generating a changelog succeeds.
141+
- name: Create Release
142+
uses: actions/create-release@v1
143+
if: >
144+
success() && (
145+
steps.to_do.outputs.should_release == 'true' ||
146+
steps.publish.outputs.version_override != ''
147+
)
148+
with:
149+
tag_name: ${{ steps.versions.outputs.last_tag }}
150+
release_name: Release ${{ steps.versions.outputs.crate_version }}
151+
body: ${{ steps.git-cliff.outputs.content }}
152+
draft: false
153+
prerelease: false
154+
env:
155+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/overall-coverage.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)