Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This private action setups all the necessary to run on all the workflows.
#
# By default it installs rust considering the input 'rust-toolchain' to choose
# which toolchain to install, then installs all the required rust packages.
#
# If there is an npm package specified then it also installs node along
# the required packages.

name: Setup Environment

inputs:
rust-toolchain:
required: false
default: stable
rust-components:
required: false
default: ""
rust-packages:
required: false
default: ""
npm-packages:
required: false
default: ""

runs:
using: "composite"
steps:
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "22.18.0"


- name: Configure GIT
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"


- name: Setup Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: ${{ inputs.rust-toolchain }}
components: ${{ inputs.rust-components }}


- name: Set Rust Bin Environment Variable
shell: bash
run: echo "PATH=$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV


- uses: cargo-bins/cargo-binstall@main
- name: Install Rust Packages
if: ${{ inputs.rust-packages != '' }}
shell: bash
run: cargo binstall --force -y ${{ inputs.rust-packages }}


- name: Install NPM Packages
if: ${{ inputs.npm-packages != '' }}
shell: bash
run: npm install -g ${{ inputs.npm-packages }}
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## Changes
Expand Down
104 changes: 104 additions & 0 deletions .github/workflows/010-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# This workflow decides whether a new version should be published,
# basically by running tests, lints and version checks to ensure
# everything is as it should be.
#
# This will fail in case
# - Any of the past commits don't follow the conventional commits standard.
# - Cargo Clippy reports a broken rule.
# - Cargo Fmt reports a broken rule.
# - Tests fail
# - Code coverage reports < 80% coverage.
#
# For now this only runs on main and on linux, since this is a library,
# once further standards are enforced this might change.

name: tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
tests:
runs-on: ubuntu-latest
permissions:
actions: read

steps:
# Need to checkout the repository before
# using composite action to setup.
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0


# Setup the environment with default
# programs and setup required packages.
- name: Setup Environment
uses: ./.github/actions/setup
with:
rust-toolchain: nightly
rust-components: llvm-tools-preview rustfmt clippy
rust-packages: cargo-llvm-cov


# Validate conventional commits from the
# current branch.
- name: Conventional Commit Validation
uses: webiny/[email protected]
with:
allowed-commit-types: "feat,fix,docs,test,ci,refactor,perf,chore,revert"


# Run code lints and tests
- name: Run Code Lint Checks And Tests
run: |
make test-code;
make test-format;
make test-clippy;


# Generate code coverage, this only
# happens in main because its the only
# branch we consideer for coverage.
- name: Generate Code Coverage
if: success() && github.ref == 'refs/heads/main'
run: make test-coverage-export;


# Upload the coverage to codecov
# Only main is considered because
# codecov is known to fail on other
# branches due to branch protection
# rules.
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
if: success() && github.ref == 'refs/heads/main'
with:
file: coverage.lcov
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
slug: FlakySL/actix_failwrap
verbose: true


# This is more relevant while merging.
# Since by merge rules we deny failed
# workflows, in the case where coverage is
# below 80% the workflow will fail thus
# The branch won't be able to be merged.
- name: Fail if overall coverage is below 80%
run: |
coverage=$(make test-coverage-get);
coverage=${coverage//[[:space:]};
coverage=${coverage%.*}
if (( coverage < 80 ))
then
echo "❌ Coverage is below 80% ($coverage%)"
exit 1
else
echo "✅ Coverage meets requirement ($coverage%)"
fi
155 changes: 155 additions & 0 deletions .github/workflows/020-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# This action will keep track of the current crate verision, the last
# pushed git tag and determine whether the project should be deployed
#
# Additionally it will keep track whether THE LAST TAG has a release
# assigned, if it doesn't unless otherwise specified it will attempt
# to create one.

name: publish

on:
workflow_run:
workflows:
- tests
types:
- completed

jobs:
publish:
runs-on: ubuntu-latest
# This only runs on main after tests have concluded successfully.
if: github.ref == 'refs/heads/main' && github.event.workflow_run.conclusion == 'success'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write

steps:
# Need to checkout the repository before
# using composite action to setup.
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0


# Setup the environment with default
# programs and setup required packages.
- name: Setup Environment
uses: ./.github/actions/setup
with:
npm-packages: "semver"


# Parsing all the previous versions
# is essential to determining whether a new
# version should be published.
#
# This exports the crate version and the
# latest git tag which help determine whether
# a new version should be published.
- name: Get And Parse Repository Versions
id: versions
run: |
# The version of the main crate which should be the first on the list in the workspace config.
echo "crate_version=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')" \
>> $GITHUB_OUTPUT;

# The last pushed git tag if any.
last_git_tag="$(git describe --tags --abbrev=0 || echo '')";
if [[ -z "$last_git_tag" ]]; then exit 0; fi;
echo "last_tag=$last_git_tag" >> $GITHUB_OUTPUT;


# In the case the last git tag is minor than
# the current crate version, determine that
# a new version should be published to crates.io.
#
# In the case the last git tag doesn't have
# a release associated to it, determine a release
# should be created with git cliff.
- name: Determine What Should Be Done
id: to_do
run: |
crate_version="${{ steps.versions.outputs.crate_version }}";
last_tag="${{ steps.versions.outputs.last_tag }}";

# If there is no last tag, make up 0.0.0.
if [ -z "$last_tag" ]; then
last_tag="0.0.0"
fi

# If the last published tag is minor than the crate's tag
# determine that the crate should be published.
if semver -r "> $last_tag" "$crate_version"; then
echo "should_publish=true" >> $GITHUB_OUTPUT
else
echo "should_publish=false" >> $GITHUB_OUTPUT
fi

# If there is no release associated to the last tag
# determine that a release should be created.
if ! gh release view "$last_tag" >/dev/null 2>&1; then
echo "should_release=true" >> $GITHUB_OUTPUT;
else
echo "should_release=false" >> $GITHUB_OUTPUT;
fi


# In the case it's determined that the crate should be
# published, then we call cargo publish and create
# a new tag for the publication in the case the publication
# succeeded.
- name: Publish And Create A New Tag
id: publish
if: success() && steps.to_do.outputs.should_publish == 'true'
run: |
crate_version="${{ steps.versions.outputs.crate_version }}"

# If cargo publish fails a new release won't be made.
# Make sure that it exits in case github actions doesn't halt.
cargo publish || exit 1;

git tag "$crate_version";
git push origin "$crate_version";

# We make a version override for which the changelog
# will be created instead.
echo "version_override=$crate_version" >> $GITHUB_OUTPUT;


# In the case that or either it's determined that
# a release should be created or a new publication
# is done, then we call git-cliff-action@v4 to process
# creating a changelog.
- name: Generate a changelog
uses: orhun/git-cliff-action@v4
if: >
success() && (
steps.to_do.outputs.should_release == 'true' ||
steps.publish.outputs.version_override != ''
)
id: git-cliff
with:
config: cliff.toml
args: --verbose --latest --strip header


# We call create-release@v1 in the case the same
# condition as generating a changelog succeeds.
- name: Create Release
uses: actions/create-release@v1
if: >
success() && (
steps.to_do.outputs.should_release == 'true' ||
steps.publish.outputs.version_override != ''
)
with:
tag_name: ${{ steps.versions.outputs.last_tag }}
release_name: Release ${{ steps.versions.outputs.crate_version }}
body: ${{ steps.git-cliff.outputs.content }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 changes: 0 additions & 52 deletions .github/workflows/overall-coverage.yml

This file was deleted.

Loading