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

ci: refactor cargo build and cargo clippy workflow #1350

Merged
merged 4 commits into from
Aug 23, 2023
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: 0 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ You could link a pull request to an issue by using a supported keyword in the pu

**CI Switch**

- [ ] Cargo Clippy
- [ ] Coverage Test
- [ ] E2E Tests
- [ ] Code Format
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/axon-start-with-short-genesis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ jobs:
await waitXBlocksPassed('http://127.0.0.1:8000', 2);
EOF
timeout-minutes: 1

- name: Archive logs
if: always()
if: failure()
uses: actions/upload-artifact@v3
with:
name: single-axon-node-logs
Expand Down Expand Up @@ -113,7 +114,7 @@ jobs:
timeout-minutes: 1

- name: Archive logs
if: always()
if: failure()
uses: actions/upload-artifact@v3
with:
name: multi-axon-nodes-logs
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Build Axon Binary

on:
push:
pull_request:
merge_group:
workflow_dispatch:
# Rather than copying and pasting from one workflow to another, you can make workflows reusable.
# See https://docs.github.com/en/actions/using-workflows/reusing-workflows
Expand Down
152 changes: 38 additions & 114 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -1,124 +1,48 @@
name: Cargo Clippy

on:
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened ]
merge_group:
workflow_dispatch:
inputs:
dispatch:
type: string
description: "Dispatch contains pr context that want to trigger cargo cllipy"
required: true

# Ensure that only a single job or workflow using the same concurrency group will run at a time.
# see https://docs.github.com/en/actions/using-jobs/using-concurrency#example-only-cancel-in-progress-jobs-or-runs-for-the-current-workflow
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
# only needs to check a group's latest commit
cancel-in-progress: true

jobs:
Dispatch-Clippy:
if: contains(github.event_name, 'workflow_dispatch')
runs-on: ubuntu-latest
outputs:
output-sha: ${{ steps.escape_multiple_lines_test_inputs.outputs.result }}
cargo-clippy:
strategy:
matrix:
# Supported GitHub-hosted runners and hardware resources
# see https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
os: [ubuntu-22.04]
fail-fast: false
runs-on: ${{ matrix.os }}

steps:
- name: Generate axon-bot token
if: contains(github.event_name, 'workflow_dispatch') &&
github.repository_owner == 'axonweb3' && github.event.inputs.dispatch != 'regression'
id: generate_axon_bot_token
uses: wow-actions/use-app-token@v2
with:
app_id: ${{ secrets.AXON_BOT_APP_ID }}
private_key: ${{ secrets.AXON_BOT_PRIVATE_KEY }}
- name: Event is dispatch
if: contains(github.event_name, 'workflow_dispatch') &&
github.repository_owner == 'axonweb3' && github.event.inputs.dispatch != 'regression'
uses: actions/github-script@v6
id: get_sha
with:
github-token: ${{ steps.generate_axon_bot_token.outputs.BOT_TOKEN }}
script: |
const dispatch = JSON.parse(`${{ github.event.inputs.dispatch }}`);
const pr = (
await github.rest.pulls.get({
owner: dispatch.repo.owner,
repo: dispatch.repo.repo,
pull_number: dispatch.issue.number,
})
).data.head;
github.rest.repos.createCommitStatus({
state: 'pending',
owner: dispatch.repo.owner,
repo: dispatch.repo.repo,
context: '${{ github.workflow }}',
sha: pr.sha,
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
})
return pr.sha
- name: Escape multiple lines test inputs
if: contains(github.event_name, 'workflow_dispatch') &&
github.repository_owner == 'axonweb3' && github.event.inputs.dispatch != 'regression'
id: escape_multiple_lines_test_inputs
run: |
inputs=${{ steps.get_sha.outputs.result}}
inputs="${inputs//'%'/'%25'}"
inputs="${inputs//'\n'/'%0A'}"
inputs="${inputs//'\r'/'%0D'}"
echo "result=$inputs" >> $GITHUB_OUTPUT
- name: Git checkout
uses: actions/checkout@v3
with:
ref: ${{ steps.escape_multiple_lines_test_inputs.outputs.result || 'main' }}
- uses: lyricwulf/abc@v1
with:
linux: m4
- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustfmt, clippy
- uses: actions/checkout@v3

- name: cargo-clippy
run: make clippy && git diff --exit-code Cargo.lock
- name: Cache of Cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-clippy
${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo

finally:
name: Finally
needs: [ Dispatch-Clippy ]
if: always() && contains(github.event_name, 'workflow_dispatch') &&
github.event.inputs.dispatch != 'regression' && github.repository_owner == 'axonweb3'
runs-on: ubuntu-latest
steps:
- name: Generate axon-bot token
id: generate_axon_bot_token
uses: wow-actions/use-app-token@v2
with:
app_id: ${{ secrets.AXON_BOT_APP_ID }}
private_key: ${{ secrets.AXON_BOT_PRIVATE_KEY }}
- if: contains(join(needs.*.result, ';'), 'failure') || contains(join(needs.*.result, ';'), 'cancelled')
run: exit 1
- uses: actions/github-script@v6
if: ${{ always() }}
with:
github-token: ${{ steps.generate_axon_bot_token.outputs.BOT_TOKEN }}
script: |
github.rest.repos.createCommitStatus({
state: '${{ job.status }}',
owner: context.repo.owner,
repo: context.repo.repo,
context: '${{ github.workflow }}',
sha: '${{ needs.Dispatch-Clippy.outputs.output-sha || 'main'}}',
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
})
Clippy:
if: |
(contains(fromJson('["dependabot[bot]" ]'), github.actor) && github.event_name == 'pull_request') ||
(contains(github.event_name, 'push') && github.ref == 'refs/heads/main' )
runs-on: ubuntu-latest
steps:
- uses: lyricwulf/abc@v1
with:
linux: m4
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
components: rustfmt, clippy
- name: Install cargo-clippy
run: rustup component add clippy

- name: Run cargo-clippy in Makefile
run: make clippy && git diff --exit-code Cargo.lock

- name: cargo-clippy
run: make clippy && git diff --exit-code Cargo.lock
- run: ls -lh target