I have configured a GitHub Actions workflow and created a check for the workflow to pass before any PR can be merged.
Below is my ci.yaml
:
<code>name: Combined Test
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
concurrency:
# Cancel older, in-progress jobs from the same PR, same workflow.
# use run_id if the job is triggered by a push to ensure
# push-triggered jobs do not get canceled.
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
foundry-test:
name: Foundry Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Run tests
id: run_tests
run: forge test -vvv
- name: Run snapshot
run: forge snapshot
ape-test:
name: Ape Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run Ape tests
id: run_ape_tests
run: ape test -s
</code>
<code>name: Combined Test
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
concurrency:
# Cancel older, in-progress jobs from the same PR, same workflow.
# use run_id if the job is triggered by a push to ensure
# push-triggered jobs do not get canceled.
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
foundry-test:
name: Foundry Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Run tests
id: run_tests
run: forge test -vvv
- name: Run snapshot
run: forge snapshot
ape-test:
name: Ape Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run Ape tests
id: run_ape_tests
run: ape test -s
</code>
name: Combined Test
on:
push:
branches: [master, develop]
pull_request:
branches: [master, develop]
concurrency:
# Cancel older, in-progress jobs from the same PR, same workflow.
# use run_id if the job is triggered by a push to ensure
# push-triggered jobs do not get canceled.
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
foundry-test:
name: Foundry Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Run tests
id: run_tests
run: forge test -vvv
- name: Run snapshot
run: forge snapshot
ape-test:
name: Ape Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run Ape tests
id: run_ape_tests
run: ape test -s
The CI status for some reason is never successful. What am I missing?
Git CI Action
I tried to set the CI status with my personal access token (PAT) using below code:
<code> set-ci-status:
name: Set CI Status on Success
runs-on: ubuntu-latest
needs: [foundry-test, ape-test]
if: ${{ always() }}
steps:
- name: Set CI status on success
if: ${{ success() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT }}
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: 'success',
target_url: process.env.GITHUB_RUN_URL,
description: 'All tests passed',
context: 'ci status'
});
</code>
<code> set-ci-status:
name: Set CI Status on Success
runs-on: ubuntu-latest
needs: [foundry-test, ape-test]
if: ${{ always() }}
steps:
- name: Set CI status on success
if: ${{ success() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT }}
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: 'success',
target_url: process.env.GITHUB_RUN_URL,
description: 'All tests passed',
context: 'ci status'
});
</code>
set-ci-status:
name: Set CI Status on Success
runs-on: ubuntu-latest
needs: [foundry-test, ape-test]
if: ${{ always() }}
steps:
- name: Set CI status on success
if: ${{ success() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT }}
script: |
github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: 'success',
target_url: process.env.GITHUB_RUN_URL,
description: 'All tests passed',
context: 'ci status'
});
But GitHub requires that the CI status should be reported by GitHub app not using PAT.
Git CI snap
New contributor
Shubham Kumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.