ci: use caching from docker to run test in CI #481
Workflow file for this run
This file contains 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: Build and Test | |
on: | |
push: | |
branches: | |
- main | |
- develop | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
check-contribution: | |
name: Check if changelog and version have been updated | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Check contributions | |
if: ${{ github.event.pull_request.base.sha }} | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email github-actions[bot]@users.noreply.github.com | |
git fetch origin main ${{ github.event.pull_request.base.sha }} ${{ github.head_ref }} | |
git checkout ${{ github.head_ref }} | |
VER_DIFF=$(git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- ./VERSION) | |
if ! [ "${VER_DIFF}" ]; then | |
bash update_version.sh --commit && git push | |
fi | |
CL_DIFF=$(git diff ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- ./CHANGELOG.md) | |
if ! [ "${CL_DIFF}" ]; then | |
SEARCH_STRING="## Upcoming changes (in development)" | |
NEW_TITLE="${{ github.event.pull_request.title }} (#${{ github.event.pull_request.number }})" | |
sed -z "s/${SEARCH_STRING}\n/${SEARCH_STRING}\n\n- ${NEW_TITLE}/" -i CHANGELOG.md | |
git add CHANGELOG.md && git commit -m "Update CHANGELOG" && git push | |
fi | |
shell: bash | |
check-skippable-changes: | |
name: Check skippable changes | |
runs-on: ubuntu-latest | |
outputs: | |
skip: ${{ steps.check_if_skippable.outputs.should_skip }} | |
steps: | |
- id: check_if_skippable | |
uses: fkirc/skip-duplicate-actions@master | |
with: | |
cancel_others: 'true' | |
do_not_skip: '["workflow_dispatch"]' | |
paths_ignore: '["**.md", ".**/**", "**.gitignore"]' | |
skip_after_successful_duplicate: 'true' | |
build-test: | |
needs: check-skippable-changes | |
if: ${{ needs.check-skippable-changes.outputs.skip != 'true' }} | |
runs-on: ubuntu-latest | |
name: Run tests | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build Cache for Docker | |
uses: actions/cache@v3 | |
with: | |
path: build-cache | |
key: ${{ runner.os }}-build-cache-${{ hashFiles('./') }} | |
- name: Inject build-cache into docker | |
uses: reproducible-containers/[email protected] | |
with: | |
cache-source: build-cache | |
cache-target: /build | |
- name: Build and Test | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
target: python-test | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |