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

add github workflows #297

Merged
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
1 change: 1 addition & 0 deletions .github/env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IMAGE="docker.io/paritytech/ci-unified:bullseye-1.81.0-2024-11-19-v202411281558"
104 changes: 104 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Checks

on:
push:
branches:
- main
paths:
- '.snippets/code/**'
- '.github/workflows/**'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the CI runs once when the PR is opened, when it receives a new commit, and when it is ready for review?

Perhaps it is good to remove ready_for_review to reduce the number of runs a bit?

Or does this mean that if the PR is draft the CI won't run? that would be a good outcome :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the CI runs once when the PR is opened, when it receives a new commit, and when it is ready for review?

Yes and also when a closed PR is re-opened.

Or does this mean that if the PR is draft the CI won't run? that would be a good outcome :)

Yes the CI won't run in draft mode. Once it is published, the CI would run. For, any commits after opening the PR, the CI would run as well which is ideal.

paths:
- '.snippets/code/**'
- '.github/workflows/**'
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
preflight:
uses: ./.github/workflows/reusable-preflight.yml

fmt:
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [preflight]
container:
image: ${{ needs.preflight.outputs.IMAGE }}
steps:
- uses: actions/checkout@v4
- name: Cargo fmt
working-directory: .snippets/code
run: cargo +nightly fmt --all -- --check

clippy:
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [preflight]
container:
image: ${{ needs.preflight.outputs.IMAGE }}
steps:
- uses: actions/checkout@v4
- name: Clippy check
working-directory: .snippets/code
run: |
cargo clippy --all-targets --locked --workspace --quiet
cargo clippy --all-targets --all-features --locked --workspace --quiet

test:
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [preflight]
container:
image: ${{ needs.preflight.outputs.IMAGE }}
steps:
- uses: actions/checkout@v4
- name: Run tests
working-directory: .snippets/code
run: cargo test

check-fail-ci:
runs-on: ubuntu-latest
container:
image: "paritytech/tools:latest"
options: --user root
steps:
- uses: actions/checkout@v4
- name: Check
working-directory: .snippets/code
run: |
set +e
rg --line-number --hidden --type rust --glob '!{.git,target}' "$ASSERT_REGEX" .; exit_status=$?
if [ $exit_status -eq 0 ]; then
echo "$ASSERT_REGEX was found, exiting with 1";
exit 1;
else
echo "No $ASSERT_REGEX was found, exiting with 0";
exit 0;
fi
env:
ASSERT_REGEX: "FAIL-CI"
GIT_DEPTH: 1

confirm-checks:
runs-on: ubuntu-latest
name: All checks passed
needs:
- fmt
- clippy
- test
- check-fail-ci
if: always() && !cancelled()
steps:
- run: |
tee resultfile <<< '${{ toJSON(needs) }}'
FAILURES=$(cat resultfile | grep '"result": "failure"' | wc -l)
if [ $FAILURES -gt 0 ]; then
echo "### At least one required job failed ❌" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo '### Good job! All the required jobs passed 🚀' >> $GITHUB_STEP_SUMMARY
fi
48 changes: 48 additions & 0 deletions .github/workflows/reusable-preflight.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Preflight

on:
workflow_call:
outputs:
changes_rust:
value: ${{ jobs.preflight.outputs.changes_rust }}
changes_currentWorkflow:
value: ${{ jobs.preflight.outputs.changes_currentWorkflow }}
IMAGE:
value: ${{ jobs.preflight.outputs.IMAGE }}
description: "CI image"

jobs:
preflight:
runs-on: ubuntu-latest
outputs:
changes_rust: ${{ steps.set_changes.outputs.rust_any_changed || steps.set_changes.outputs.currentWorkflow_any_changed }}
changes_currentWorkflow: ${{ steps.set_changes.outputs.currentWorkflow_any_changed }}
IMAGE: ${{ steps.set_image.outputs.IMAGE }}

steps:
- uses: actions/checkout@v4

- name: Current file
id: current_file
shell: bash
run: |
echo "currentWorkflowFile=$(echo ${{ github.workflow_ref }} | sed -nE "s/.*(\.github\/workflows\/[a-zA-Z0-9_-]*\.y[a]?ml)@refs.*/\1/p")" >> $GITHUB_OUTPUT
echo "currentActionDir=$(echo ${{ github.action_path }} | sed -nE "s/.*(\.github\/actions\/[a-zA-Z0-9_-]*)/\1/p")" >> $GITHUB_OUTPUT

- name: Set changes
id: set_changes
uses: tj-actions/changed-files@v45
with:
files_yaml: |
rust:
- '.snippets/code/**/*'
- '!.github/**/*'
- '!docs/**/*'
currentWorkflow:
- '${{ steps.current_file.outputs.currentWorkflowFile }}'
- '.github/workflows/reusable-preflight.yml'

- name: Set image
id: set_image
shell: bash
run: cat .github/env >> $GITHUB_OUTPUT
Loading