-
Notifications
You must be signed in to change notification settings - Fork 1
120 lines (99 loc) · 3.4 KB
/
ci-cd.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
name: CI/CD
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
release:
types: [published]
defaults:
run:
shell: bash
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest] # , macos-latest, windows-latest]
python-version: ["3.10", "3.11"]
fail-fast: false
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v2
- name: Disable etelemetry
run: echo "NO_ET=TRUE" >> $GITHUB_ENV
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
# - name: Install other dependencies
# run: |
# sudo apt-get update
# sudo apt-get install -y libxml2-dev libxslt-dev git dcmtk
- name: Install Minconda
uses: conda-incubator/setup-miniconda@v2
with:
auto-activate-base: true
activate-environment: ""
- name: Install MRtrix via Conda
run: |
conda install -c mrtrix3 mrtrix3
mrconvert --version
- name: Update build tools
run: python${{ matrix.python-version }} -m pip install --upgrade pip
- name: Install Xnat-Ingest
run: python${{ matrix.python-version }} -m pip install .[test]
- name: Save XNAT username/password in ~/.netrc
run: |
echo "machine localhost:8080" > $HOME/.netrc
echo "user admin" >> $HOME/.netrc
echo "password admin" >> $HOME/.netrc
- name: Pytest
run: pytest -vvs --cov xnat_ingest --cov-config .coveragerc --cov-report xml .
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
deploy:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v2
- name: Unset header
# checkout@v2 adds a header that makes branch protection report errors
# because the Github action bot is not a collaborator on the repo
run: git config --local --unset http.https://github.com/.extraheader
- name: Fetch tags
run: git fetch --prune --unshallow
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get version from latest git tag and construct image tags
id: versions
run: |
VERSION=$(git describe --tags --abbrev=0)
IMAGE=${{ env.REGISTRY }}/$(echo "${{ env.IMAGE_NAME }}" | awk '{print tolower($0)}')
echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT
echo "TAG=$IMAGE:$VERSION" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
cache-from: type=registry,ref=${{ steps.versions.outputs.IMAGE }}:buildcache
cache-to: type=registry,ref=${{ steps.versions.outputs.IMAGE }}:buildcache,mode=max
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name == 'release' }}
tags: |
${{ steps.versions.outputs.TAG }}
${{ steps.versions.outputs.IMAGE }}:latest