-
Notifications
You must be signed in to change notification settings - Fork 14
102 lines (88 loc) · 3.74 KB
/
docker-build-test-upload.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
name: Build Docker image
on:
pull_request:
push:
branches:
- main
tags:
- v*
workflow_dispatch:
env:
FORCE_COLOR: 1
IMAGE: ghcr.io/aiidalab/qe
BUILDKIT_PROGRESS: plain
# https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
# only cancel in-progress jobs or runs for the current workflow - matches against branch & tags
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-test-upload:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout Repo ⚡️
uses: actions/checkout@v4
- name: Login to Container Registry 🔑
uses: docker/login-action@v2
if: ${{ !github.event.pull_request.head.repo.fork }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta 📝
id: meta
uses: docker/metadata-action@v5
with:
images: |
name=${{ env.IMAGE }}
tags: |
type=ref,event=pr
type=edge,enable={{is_default_branch}}
type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Build and push image
id: build-upload
uses: docker/build-push-action@v5
with:
tags: ${{ steps.meta.outputs.tags }}
load: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork }}
push: ${{ ! (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork) }}
context: .
platforms: linux/amd64
cache-to: |
type=gha,scope=${{ github.workflow }},mode=min
cache-from: |
type=gha,scope=${{ github.workflow }}
- name: Set Up Python 🐍
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install Dev Dependencies 📦
run: pip install -r requirements-docker.txt
- name: Set jupyter token env
run: echo "JUPYTER_TOKEN=$(openssl rand -hex 32)" >> $GITHUB_ENV
- name: Run pytest for Chrome
run: pytest -sv --driver Chrome tests_integration/
env:
# We'd like to identify the image by its unique digest, i.e ghcr.io/aiidalab/qe@sha256:<digest>
# but that sadly does not work when the image is loaded to Docker locally and not published on ghcr.io
# as is the case for PRs from forks. Hence this super-ugly ternary expression...
# For forks, we take the image as ghcr.io/aiidalab/qe:pr-XXX
# which is stored in the steps.meta.outputs.tags variable
QE_IMAGE: >-
${{
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork &&
steps.meta.outputs.tags ||
format('{0}@{1}', env.IMAGE, steps.build-upload.outputs.imageid)
}}
- name: Upload screenshots as artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: Screenshots
path: screenshots/
if-no-files-found: error