ci(repo): Improve repo tooling #525
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
workflow_dispatch: | |
pull_request: | |
types: [opened, synchronize, edited, reopened] | |
push: | |
branches: [main] | |
env: | |
CARGO_TERM_COLOR: always | |
CLICOLOR: 1 | |
RUST_VERSION: 1.79.0 | |
RUST_NIGHTLY_VERSION: "nightly-2024-07-28" | |
CI: true | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
validate-title: | |
name: Validate PR Title | |
runs-on: ubuntu-latest | |
steps: | |
- uses: amannn/action-semantic-pull-request@v5 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
requireScope: true | |
subjectPattern: ^([A-Z]).+$ | |
types: | | |
build | |
ci | |
docs | |
feat | |
fix | |
perf | |
refactor | |
test | |
scopes: | | |
benches | |
repo | |
deps | |
release | |
core | |
publisher | |
data-parser | |
fuel-streams | |
lockfile: | |
name: Validate Lockfile | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: ./.github/actions/setup-rust | |
- uses: Swatinem/rust-cache@v2 | |
- run: cargo update --workspace --locked | |
pre-commit: | |
name: Pre-commit | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./.github/actions/setup-rust | |
with: | |
toolchain: ${{ env.RUST_NIGHTLY_VERSION }} | |
- uses: actions/setup-python@v3 | |
- uses: pre-commit/action@v3.0.1 | |
commitlint: | |
name: Validating commits | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node && PNPM | |
uses: ./.github/actions/setup-node | |
- name: Install commitlint | |
run: | | |
npm install commitlint@latest | |
npm install @commitlint/config-conventional | |
- name: Validate current commit (last commit) with commitlint | |
if: github.event_name == 'push' | |
run: npx commitlint --config ./.commitlintrc.yaml --last --verbose | |
- name: Validate PR commits with commitlint | |
if: github.event_name == 'pull_request' | |
run: | | |
npx commitlint \ | |
--config ./.commitlintrc.yaml \ | |
--from ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} \ | |
--to ${{ github.event.pull_request.head.sha }} \ | |
--verbose | |
publish-crates-check: | |
name: Publish Check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: ./.github/actions/setup-rust | |
- uses: Swatinem/rust-cache@v2 | |
- name: Publish crate check | |
uses: FuelLabs/publish-crates@v1 | |
with: | |
dry-run: true | |
check-repo: false | |
ignore-unpublished-changes: true | |
cargo-verifications: | |
needs: | |
- pre-commit | |
- lockfile | |
- commitlint | |
- publish-crates-check | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: ./.github/actions/setup-rust | |
with: | |
toolchain: stable | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
cache-on-failure: true | |
- name: Check for typos | |
uses: crate-ci/typos@master | |
with: | |
config: ./typos.toml | |
- uses: taiki-e/install-action@cargo-machete | |
- name: Check unused dependencies | |
run: cargo machete --skip-target-dir | |
- name: Lint project | |
run: make lint | |
test: | |
needs: | |
- cargo-verifications | |
name: Cargo Tests | |
runs-on: ubuntu-latest | |
env: | |
NATS_URL: nats://127.0.0.1:4222 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: ./.github/actions/setup-rust | |
with: | |
toolchain: stable | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
cache-on-failure: true | |
- name: Set up Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.20" | |
- name: Install nats-io/nkeys | |
run: | | |
go install github.com/nats-io/nkeys/nk@latest | |
echo "$HOME/go/bin" >> $GITHUB_PATH | |
- name: Generate NATS NKeys | |
run: | | |
NKEY_OUTPUT=$(nk -gen user -pubout) | |
echo "NATS_NKEY_SEED=$(echo "$NKEY_OUTPUT" | sed -n '1p')" >> $GITHUB_ENV | |
echo "NATS_NKEY_USER=$(echo "$NKEY_OUTPUT" | sed -n '2p')" >> $GITHUB_ENV | |
- name: Create .env file for NATS | |
run: | | |
cp .env.sample .env | |
sed -i 's/generated-nats-nkey-seed/${{ env.NATS_NKEY_SEED }}/g' .env | |
sed -i 's/generated-nats-nkey-user/${{ env.NATS_NKEY_USER }}/g' .env | |
- name: Run tests | |
run: | | |
make start/nats | |
export NATS_NKEY_SEED=${{ env.NATS_NKEY_SEED }} | |
export NATS_NKEY_USER=${{ env.NATS_NKEY_USER }} | |
make test | |
- name: Stop NATS | |
if: always() | |
run: make stop/nats | |
build: | |
needs: | |
- cargo-verifications | |
name: ${{ matrix.package}}-${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }} | |
runs-on: ${{ matrix.platform.os }} | |
env: | |
ARTIFACT_NAME: artifact | |
strategy: | |
fail-fast: false | |
matrix: | |
package: | |
- fuel-streams-publisher | |
platform: | |
# linux x86_64 | |
- os_name: Linux-x86_64-gnu | |
os: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
- os_name: Linux-x86_64-musl | |
os: ubuntu-latest | |
target: x86_64-unknown-linux-musl | |
# linux aarch64 | |
- os_name: Linux-aarch64-gnu | |
os: ubuntu-latest | |
target: aarch64-unknown-linux-gnu | |
- os_name: Linux-aarch64-musl | |
os: ubuntu-latest | |
target: aarch64-unknown-linux-musl | |
# macOS | |
- os_name: macOS-x86_64 | |
os: macOS-latest | |
target: x86_64-apple-darwin | |
- os_name: macOS-aarch64 | |
os: macOS-latest | |
target: aarch64-apple-darwin | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust | |
uses: ./.github/actions/setup-rust | |
with: | |
toolchain: stable | |
target: ${{ matrix.platform.target }} | |
sscache: "false" | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
cache-on-failure: true | |
- name: Install packages (macOS) | |
if: matrix.platform.os == 'macOS-latest' | |
run: | | |
brew install llvm | |
- name: Install cross | |
if: matrix.platform.os != 'macOS-latest' | |
uses: baptiste0928/cargo-install@v3 | |
with: | |
crate: cross | |
cache-key: ${{ matrix.job.target }} | |
git: https://github.com/cross-rs/cross | |
- name: Build with cross for Linux | |
if: matrix.platform.os != 'macOS-latest' | |
run: | | |
cross build --release --locked --target ${{ matrix.platform.target }} --package ${{ matrix.package }} | |
- name: Build with cargo for MacOS | |
if: matrix.platform.os == 'macOS-latest' | |
run: | | |
rustup target add ${{ matrix.platform.target }} | |
cargo build --release --locked --target ${{ matrix.platform.target }} --package ${{ matrix.package }} | |
- name: Strip binaries | |
run: ./scripts/strip-binary.sh "${{ matrix.platform.target }}" | |
- name: Set Artifact Name | |
run: echo "ARTIFACT_NAME=${{ matrix.package }}-${{ matrix.platform.os_name }}" >> $GITHUB_ENV | |
- name: Package as archive | |
shell: bash | |
run: | | |
cd target/${{ matrix.platform.target }}/release | |
tar czvf ../../../${{ env.ARTIFACT_NAME }}.tar.gz ${{ matrix.package }} | |
cd - | |
- name: Publish release artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
path: "${{ matrix.package }}-*" | |
if-no-files-found: error | |
release: | |
name: Create Release with Knope | |
if: (github.head_ref == 'changeset/release-main' && github.event.pull_request.merged == true) || github.event_name == 'workflow_dispatch' | |
needs: | |
- test | |
- build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
actions: write | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4.1.6 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4.1.7 | |
with: | |
path: artifacts | |
merge-multiple: true | |
- name: List Artifacts | |
run: ls -R artifacts | |
- name: Cache Artifacts | |
uses: actions/cache@v4 | |
with: | |
path: artifacts | |
key: ${{ runner.os }}-artifacts-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-artifacts- | |
- name: Run Knope Action | |
uses: knope-dev/action@v2.1.0 | |
with: | |
github-token: ${{ secrets.REPO_TOKEN }} | |
- name: Knope Release | |
run: knope release | |
env: | |
github-token: ${{ secrets.REPO_TOKEN }} | |
publish-crates: | |
name: Publish on Crates.io | |
needs: | |
- publish-crates-check | |
- release | |
runs-on: buildjet-4vcpu-ubuntu-2204 | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Restore Artifacts Cache | |
uses: actions/cache@v4 | |
with: | |
path: artifacts | |
key: ${{ runner.os }}-artifacts-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-artifacts- | |
- name: Install Rust Toolchain | |
uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ env.RUST_VERSION }} | |
targets: wasm32-unknown-unknown | |
- name: Publish Crate | |
uses: FuelLabs/publish-crates@v1 | |
with: | |
publish-delay: 60000 | |
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} |