forked from openjournals/inara
-
Notifications
You must be signed in to change notification settings - Fork 2
91 lines (82 loc) · 3.23 KB
/
Copy pathbuild.yaml
File metadata and controls
91 lines (82 loc) · 3.23 KB
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
name: Image Builder
on:
push:
# Build and publish after updating the default branch
branches:
- main
paths-ignore:
- '.dockerignore'
- 'docs/*'
- 'LICENSE'
- 'README.md'
- 'example/*'
- 'test/**'
pull_request:
# Build, and publish a staging image so the pull request can be tested
# against a real image before it is merged.
jobs:
# Build images and push them
build:
name: Build Docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# `main` keeps publishing `latest`, unchanged — it is what the preprint
# workflow pulls. A pull request publishes `staging-pr-<number>` instead,
# so a review build can never overwrite the production tag.
- name: Determine image tag
id: image
run: |
if [ '${{ github.event_name }}' = 'pull_request' ]; then
tag='staging-pr-${{ github.event.pull_request.number }}'
else
tag=latest
fi
printf 'tag=%s\n' "$tag" >> "$GITHUB_OUTPUT"
printf 'Image tag for this run: %s\n' "$tag"
- name: Build image
run: |
docker build \
--tag=${{ github.repository }}:${{ steps.image.outputs.tag }} \
--tag=ghcr.io/${{ github.repository }}:${{ steps.image.outputs.tag }} \
.
# A pull request opened from a fork has no access to secrets, so it can
# only be built, not published.
- name: Check whether this run can publish
id: publish
run: |
if [ '${{ github.repository }}' != 'neurolibre/inara' ]; then
printf 'ok=false\n' >> "$GITHUB_OUTPUT"
elif [ '${{ github.event_name }}' = 'pull_request' ] &&
[ '${{ github.event.pull_request.head.repo.full_name }}' != '${{ github.repository }}' ]; then
printf 'ok=false\n' >> "$GITHUB_OUTPUT"
printf 'Pull request is from a fork; building without publishing.\n'
else
printf 'ok=true\n' >> "$GITHUB_OUTPUT"
fi
- name: Push to Docker Hub
if: steps.publish.outputs.ok == 'true'
run: |
# Log into registry
echo "${{ secrets.DOCKER_HUB_TOKEN }}" |
docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
docker push ${{ github.repository }}:${{ steps.image.outputs.tag }}
- name: Push to GitHub Container Registry
if: steps.publish.outputs.ok == 'true'
run: |
# Log into registry
echo "${{ secrets.GITHUB_TOKEN }}" | \
docker login ghcr.io \
-u ${{ github.actor }} \
--password-stdin
docker push ghcr.io/${{ github.repository }}:${{ steps.image.outputs.tag }}
- name: Summarise how to use the image
if: steps.publish.outputs.ok == 'true'
run: |
{
printf 'Pushed `%s:%s`\n\n' \
'${{ github.repository }}' '${{ steps.image.outputs.tag }}'
printf 'Build a paper with it:\n\n'
printf '```\ndocker run --rm -v "$PWD:/data" %s:%s -o neurolibre ./paper.md\n```\n' \
'${{ github.repository }}' '${{ steps.image.outputs.tag }}'
} >> "$GITHUB_STEP_SUMMARY"