Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refac CI: reorganize it and make it run faster for PRs #739

Merged
merged 7 commits into from
Nov 17, 2024
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
17 changes: 17 additions & 0 deletions .github/workflows/all-tests-slow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Run tests for all combinations

on:
schedule:
- cron: "0 0 1,15 * *" # biweekly
push:
branches:
- main
paths-ignore:
- "*.md"

jobs:
run-tests-for-all-combinations:
uses: ./.github/workflows/build-artifacts-and-run-tests.yml
with:
matrix_all_combinations: true
upload_artifacts: false
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
name: build-and-test
# This is a reusable workflow

name: Build artifacts and run tests

on:
push:
branches:
- main
tags:
- "[0-9]+.[0-9]+.[0-9]+"
pull_request:
workflow_dispatch:
inputs:
matrix_all_combinations:
description: "if matrix should have all combinations of targets and features"
type: boolean
required: true
default: true
upload_artifacts:
description: "if built artifacts should be uploaded"
type: boolean
required: true
default: true
workflow_call:
inputs:
matrix_all_combinations:
description: "if matrix should have all combinations of targets and features"
type: boolean
required: true
upload_artifacts:
description: "if built artifacts should be uploaded"
type: boolean
required: true

jobs:
build:
name: build
runs-on: ${{ matrix.os }}
build-artifacts-and-run-tests:
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
env:
CARGO: cargo
strategy:
fail-fast: false
matrix:
feature-unrar: ${{ inputs.matrix_all_combinations && fromJSON('[true, false]') || fromJSON('[false]')}}
feature-use-zlib: ${{ inputs.matrix_all_combinations && fromJSON('[true, false]') || fromJSON('[false]')}}
feature-use-zstd-thin: ${{ inputs.matrix_all_combinations && fromJSON('[true, false]') || fromJSON('[false]')}}
target:
# native
- x86_64-unknown-linux-gnu
Expand All @@ -30,13 +50,8 @@ jobs:
- aarch64-unknown-linux-musl
- armv7-unknown-linux-gnueabihf
- armv7-unknown-linux-musleabihf
feature-use-zlib: [true, false]
feature-use-zstd-thin: [true, false]
feature-unrar: [true, false]

include:
# default runner
- os: ubuntu-latest
# runner overrides
- target: x86_64-pc-windows-gnu
os: windows-latest
Expand All @@ -57,6 +72,13 @@ jobs:
use-cross: true
- target: armv7-unknown-linux-musleabihf
use-cross: true
# features (unless `matrix_all_combinations` is true, we only run these on linux-gnu)
- feature-unrar: true
target: x86_64-unknown-linux-gnu
- feature-use-zlib: true
target: x86_64-unknown-linux-gnu
- feature-use-zstd-thin: true
target: x86_64-unknown-linux-gnu

steps:
- name: Checkout
Expand All @@ -77,9 +99,9 @@ jobs:
shell: bash
run: |
FEATURES=()
if [[ ${{ matrix.feature-use-zlib }} == true ]]; then FEATURES+=(use_zlib); fi
if [[ ${{ matrix.feature-use-zstd-thin }} == true ]]; then FEATURES+=(use_zstd_thin); fi
if [[ ${{ matrix.feature-unrar }} == true ]]; then FEATURES+=(unrar); fi
if [[ "${{ matrix.feature-use-zlib }}" == true ]]; then FEATURES+=(use_zlib); fi
if [[ "${{ matrix.feature-use-zstd-thin }}" == true ]]; then FEATURES+=(use_zstd_thin); fi
if [[ "${{ matrix.feature-unrar }}" == true ]]; then FEATURES+=(unrar); fi
IFS=','
echo "FEATURES=${FEATURES[*]}" >> $GITHUB_OUTPUT

Expand Down Expand Up @@ -115,47 +137,10 @@ jobs:

- name: Upload artifacts
uses: actions/upload-artifact@v4
if: ${{ inputs.upload_artifacts }}
with:
name: ouch-${{ matrix.target }}-${{ steps.concat-features.outputs.FEATURES }}
path: |
target/${{ matrix.target }}/release/ouch
target/${{ matrix.target }}/release/ouch.exe
artifacts/

clippy-rustfmt:
name: clippy-rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: "Cargo: clippy, fmt"
run: |
rustup toolchain install stable --profile minimal -c clippy
rustup toolchain install nightly --profile minimal -c rustfmt
cargo +stable clippy -- -D warnings
cargo +stable clippy --tests -- -D warnings
cargo +nightly fmt -- --check

github-release:
name: github-release
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifacts
uses: dawidd6/action-download-artifact@v3
with:
path: artifacts

- name: Package release assets
run: scripts/package-release-assets.sh

- name: Create release
uses: softprops/action-gh-release@v2
with:
draft: true
files: release/ouch-*
35 changes: 35 additions & 0 deletions .github/workflows/draft-release-automatic-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Automatic trigger draft release

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"

jobs:
call-workflow-build-artifacts-and-run-tests:
uses: ./.github/workflows/build-artifacts-and-run-tests.yml
with:
matrix_all_combinations: true
upload_artifacts: true

automated-draft-release:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs: build-artifacts-and-run-tests
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download artifacts
uses: dawidd6/action-download-artifact@v3
with:
path: artifacts

- name: Package release assets
run: scripts/package-release-assets.sh

- name: Create release
uses: softprops/action-gh-release@v2
with:
draft: true
files: release/ouch-*
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: create-draft-release-with-artifacts
name: Manual trigger draft release

on:
workflow_dispatch:
Expand All @@ -8,8 +8,7 @@ on:
required: true

jobs:
github-release:
name: github-release
create-draft-release-from-manual-trigger:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/pr-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: PR workflow

on:
pull_request:
paths-ignore:
- "*.md"

jobs:
rustfmt-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: "Cargo: fmt"
run: |
rustup toolchain install nightly --profile minimal -c rustfmt
cargo +nightly fmt -- --check

clippy-checks:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: "Cargo: clippy"
run: |
rustup toolchain install stable --profile minimal -c clippy
cargo +stable clippy -- -D warnings

build-and-test:
uses: ./.github/workflows/build-artifacts-and-run-tests.yml
with:
matrix_all_combinations: false
upload_artifacts: false