-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (109 loc) · 3.95 KB
/
ci.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
# 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: CI
on:
push:
branches:
- main
pull_request:
release:
types: [published]
env:
REGISTRY: ghcr.io/
ISPG_IMAGE: ${{ github.repository_owner }}/atmospec
jobs:
build:
runs-on: ubuntu-latest
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: 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: Build image
id: build
uses: docker/build-push-action@v5
with:
tags: ${{ steps.meta.outputs.tags }}
push: true
test:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
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
with:
environment-file: environment.yml
cache-environment: true
- 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:
if: >-
github.repository_owner == 'ispg-group'
&& (github.ref_type == 'tag' || github.ref_name == 'main')
needs:
- build
- test
permissions:
packages: write
contents: write
runs-on: ubuntu-latest
timeout-minutes: 10
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=edge
type=raw,value={{tag}},enable=${{ github.ref_type == 'tag' && ! startsWith(github.ref_name, 'v') }}
type=match,pattern=v(\d{4}\.\d{2}.\d+(-.+)?),group=1
- name: Release image
uses: akhilerm/[email protected]
with:
src: ${{ env.REGISTRY }}${{ env.ISPG_IMAGE }}@${{ needs.build.outputs.image_digest }}
dst: ${{ steps.meta.outputs.tags }}