Skip to content

CI-stable

CI-stable #541

Workflow file for this run

name: CI-stable
on:
# By default, this workflow is not triggered when a PR is merged.
pull_request:
push:
branches:
- main
schedule:
- cron: "0 6 * * *" # 6am everyday.
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: pangtao22/quasistatic_simulator_base
jobs:
detect_changes:
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.changes.outputs.setup }}
image_name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
image_tag: ${{ env.IMAGE_TAG }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
setup:
- 'setup/**'
# tag | has_changes | is_PR
# pr_** | T | T
# main | T | F
# main | F | T
# main | F | F
- name: Set image_tag main
run: echo "IMAGE_TAG=main" >> $GITHUB_ENV
- name: Set image_tag PR
if: ${{ steps.changes.outputs.setup == 'true' && github.event_name == 'pull_request' }}
run: echo "IMAGE_TAG=pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
build_and_push:
runs-on: ubuntu-latest
needs: detect_changes
steps:
- name: Checkout
uses: actions/checkout@v3
if: needs.detect_changes.outputs.has_changes == 'true'
with:
submodules: recursive
- name: Set up Docker Buildx
# We cannot just skip the job, becuase build_and_test would not run
# if this job was skipped.
if: needs.detect_changes.outputs.has_changes == 'true'
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
if: needs.detect_changes.outputs.has_changes == 'true'
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
if: needs.detect_changes.outputs.has_changes == 'true'
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
if: needs.detect_changes.outputs.has_changes == 'true'
with:
context: .
file: ./setup/base.dockerfile
push: true
# Common tags:
# pull requests: pr-<PR number>
# push to main: main
# scheduled nightly builds: main, nightly
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build_and_test:
runs-on: ubuntu-latest
needs: [detect_changes, build_and_push]
defaults:
run:
shell: bash
container:
image: ${{ needs.detect_changes.outputs.image_name }}:${{ needs.detect_changes.outputs.image_tag }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Copy resources
run: ./setup/copy_resources.sh
- name: Build qsim_cpp
run: ./setup/build_bindings.sh
- name: Run tests
run: ./setup/run_tests.sh