Skip to content

Commit

Permalink
Refactor CI (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas authored May 14, 2024
1 parent 632af42 commit 67ea933
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 50 deletions.
65 changes: 29 additions & 36 deletions .github/workflows/ci.yml → .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Publishes Docker images to Github Container Repository (ghcr.io),
# and runs the automated tests with pytest.

name: CI
name: Docker

on:
push:
Expand All @@ -21,7 +21,7 @@ jobs:

build:

runs-on: ubuntu-latest
runs-on: ubuntu-22.04
timeout-minutes: 20
permissions:
packages: write
Expand All @@ -37,48 +37,47 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}${{ env.ISPG_IMAGE }}
# Before tests pass, we tag the image by the branch name
# or by pull request number, e.g. pr-11
# https://github.com/docker/metadata-action#tags-input
# See the release workflow for the release tags.
tags: |
type=sha
type=ref,event=pr
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build image
id: build
uses: docker/build-push-action@v5
with:
tags: ${{ steps.meta.outputs.tags }}
push: true
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-latest
timeout-minutes: 10
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: Setup Python test environment
uses: mamba-org/setup-micromamba@v1
- name: Set up Python
uses: actions/setup-python@v5
with:
environment-file: environment.yml
cache-environment: true
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
Expand All @@ -87,22 +86,16 @@ jobs:
# Image that was build in the build workflow
ISPG_IMAGE: ${{ env.ISPG_IMAGE }}@${{ needs.build.outputs.image_digest }}

release:
if: >-
github.repository_owner == 'ispg-group'
&& (github.ref_type == 'tag' || github.ref_name == 'main')
needs:
- build
- test
release-ghcr:
needs: [build, test]
runs-on: ubuntu-22.04
permissions:
packages: write
contents: write
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry

- name: Login to GitHub Container Registry 🔑
uses: docker/login-action@v3
with:
registry: ghcr.io
Expand All @@ -115,11 +108,11 @@ jobs:
with:
images: ${{ env.REGISTRY }}${{ env.ISPG_IMAGE }}
tags: |
type=edge
type=raw,value={{tag}},enable=${{ github.ref_type == 'tag' && ! startsWith(github.ref_name, 'v') }}
type=ref,event=pr
type=edge,enable={{is_default_branch}}
type=match,pattern=v(\d{4}\.\d{2}.\d+(-.+)?),group=1
- name: Release image
- name: Push image
uses: akhilerm/[email protected]
with:
src: ${{ env.REGISTRY }}${{ env.ISPG_IMAGE }}@${{ needs.build.outputs.image_digest }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM aiidalab/full-stack:latest
FROM aiidalab/full-stack:aiida-2.4.3
LABEL maintainer="Daniel Hollas <[email protected]>"

USER root
Expand Down
13 changes: 0 additions & 13 deletions environment.yml

This file was deleted.

3 changes: 3 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest~=7.4
pytest-docker
requests
26 changes: 26 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file was autogenerated by uv via the following command:
# uv pip compile requirements.in
attrs==23.2.0
# via pytest-docker
certifi==2024.2.2
# via requests
charset-normalizer==3.3.2
# via requests
idna==3.7
# via requests
iniconfig==2.0.0
# via pytest
packaging==24.0
# via pytest
pluggy==1.5.0
# via pytest
pytest==7.4.4
# via
# -r requirements.in
# pytest-docker
pytest-docker==3.1.1
# via -r requirements.in
requests==2.31.0
# via -r requirements.in
urllib3==2.2.1
# via requests

0 comments on commit 67ea933

Please sign in to comment.