Skip to content

Refactor CI (#33)

Refactor CI (#33) #4

Workflow file for this run

---
# Build and test the ATMOSPEC Docker image on every push and pull request.
# Publishes Docker images to Github Container Repository (ghcr.io),
# and runs the automated tests with pytest.
name: Docker
on:
push:
branches:
- main
pull_request:
release:
types: [published]
env:
REGISTRY: ghcr.io/
ISPG_IMAGE: ${{ github.repository_owner }}/atmospec
jobs:
build:
runs-on: ubuntu-22.04
timeout-minutes: 20
permissions:
packages: write
contents: read
outputs:
image_digest: ${{ steps.build.outputs.digest }}
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image
id: build
uses: docker/build-push-action@v5
with:
tags: ${{ env.REGISTRY }}${{ env.ISPG_IMAGE }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: |
type=registry,push-by-digest=true,name-canonical=true
test:
needs: build
runs-on: ubuntu-22.04
timeout-minutes: 20
permissions:
packages: read
contents: read
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install uv
run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.1.43/uv-installer.sh | sh
- name: Install test requirements
run: uv pip install --system -r requirements.txt --no-deps
- name: Run tests
shell: bash -l {0} # required to activate the conda environment
run: pytest -vs
env:
# Image that was build in the build workflow
ISPG_IMAGE: ${{ env.ISPG_IMAGE }}@${{ needs.build.outputs.image_digest }}
release-ghcr:
needs: [build, test]
runs-on: ubuntu-22.04
permissions:
packages: write
contents: write
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry 🔑
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}${{ env.ISPG_IMAGE }}
tags: |
type=ref,event=pr
type=edge,enable={{is_default_branch}}
type=match,pattern=v(\d{4}\.\d{2}.\d+(-.+)?),group=1
- name: Push image
uses: akhilerm/[email protected]
with:
src: ${{ env.REGISTRY }}${{ env.ISPG_IMAGE }}@${{ needs.build.outputs.image_digest }}
dst: ${{ steps.meta.outputs.tags }}