-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (200 loc) · 6.77 KB
/
release.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
---
name: release
on: # yamllint disable-line rule:truthy
workflow_dispatch:
pull_request:
push:
branches:
- main
env:
IMAGE_NAME: ${{ github.repository_owner }}/ldap_sync
DOCKERHUB_ACCOUNT_NAME: determinedai
EXCHANGE_PATH: /tmp
EXCHANGE_FILE: image.tar
jobs:
build:
runs-on: ubuntu-latest
env:
BUILD_TAG: ${{ github.job }}.${{ github.run_id }}
outputs:
tag: ${{ env.BUILD_TAG }}
permissions:
contents: read
steps:
- name: work around github's inability to add a lowercase() function
run: |
# FYI: the ${name,,} structure converts all of $name to lowercase
echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> "$GITHUB_ENV"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v6
with:
push: false
# note: as this image is exported, we can only build one platform here
platforms: linux/amd64
tags: ${{ env.LC_IMAGE_NAME }}:${{ env.BUILD_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=docker,dest=${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.EXCHANGE_FILE }}
path: ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
retention-days: 1
test_docker_run:
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
steps:
- name: work around github's inability to add a lowercase() function
run: |
echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> "$GITHUB_ENV"
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.EXCHANGE_FILE }}
path: ${{ env.EXCHANGE_PATH }}
- name: Load image
run: |
docker load --input ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
docker image ls -a
- name: run test
env:
SOMEVAR: someval
run: |
docker run --rm -i $LC_IMAGE_NAME:${{ needs.build.outputs.tag }} \
/bin/echo "yay"
# TODO: add an actual test of the script
test_python_compile:
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
steps:
- name: work around github's inability to add a lowercase() function
run: |
echo "LC_IMAGE_NAME=${IMAGE_NAME,,}" >> "$GITHUB_ENV"
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.EXCHANGE_FILE }}
path: ${{ env.EXCHANGE_PATH }}
- name: Load image
run: |
docker load --input ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
docker image ls -a
- name: run test
run: |
docker run --rm $LC_IMAGE_NAME:${{ needs.build.outputs.tag }} \
python -m py_compile ldap_sync.py
release:
concurrency: # only release one build at a time
group: ldap_sync
runs-on: ubuntu-latest
needs:
- build
- test_docker_run
- test_python_compile
if: >-
github.ref == 'refs/heads/main'
&& ( github.event_name == 'push'
||
github.event_name == 'workflow_dispatch'
)
permissions:
contents: write
actions: read
checks: read
packages: write
steps:
- name: work around github's inability to add a lowercase() function
run: |
DOCKERHUB_IMAGE_NAME=${IMAGE_NAME/*\//${DOCKERHUB_ACCOUNT_NAME,,}/}
{
printf 'LC_IMAGE_NAME=%s\n' "${IMAGE_NAME,,}"
printf 'DOCKERHUB_LC_IMAGE_NAME=%s\n' "${DOCKERHUB_IMAGE_NAME,,}"
} >> "$GITHUB_ENV"
# create the release
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0 # need all refs for tag generation
- name: Auto-increment version tag
id: versionbump
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: false
DEFAULT_BUMP: minor
RELEASE_BRANCHES: main
INITIAL_VERSION: 0.0.0
DEFAULT_BRANCH: main
- name: Create Github Release
uses: ncipollo/[email protected]
with:
tag: ${{ steps.versionbump.outputs.new_tag }}
name: ${{ steps.versionbump.outputs.new_tag }}
generateReleaseNotes: true
draft: false
prerelease: false
# release with PAT to trigger actions on release
token: ${{ secrets.DETERMINED_TOKEN }}
# rebuild the container after (we need to know the tag, but we know
# this will work because it worked in the job we depend upon)
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PUBLISH_TOKEN }}
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.EXCHANGE_FILE }}
path: ${{ env.EXCHANGE_PATH }}
- name: Load image
run: |
docker load --input ${{ env.EXCHANGE_PATH }}/${{ env.EXCHANGE_FILE }}
docker image ls -a
- name: Build Docker image
uses: docker/build-push-action@v6
with:
push: true
# platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }}
ghcr.io/${{ env.LC_IMAGE_NAME }}:${{ steps.versionbump.outputs.new_tag }}
ghcr.io/${{ env.LC_IMAGE_NAME }}:latest
${{ env.DOCKERHUB_LC_IMAGE_NAME }}:${{ needs.build.outputs.tag }}
${{ env.DOCKERHUB_LC_IMAGE_NAME }}:${{ steps.versionbump.outputs.new_tag }}
${{ env.DOCKERHUB_LC_IMAGE_NAME }}:latest
cache-from: type=registry,ref=ghcr.io/${{ env.LC_IMAGE_NAME }}:latest
# cache-to: type=inline
cleanup:
runs-on: ubuntu-latest
needs:
- build
- release
if: always()
permissions:
actions: write
steps:
- name: clean up ${{ env.EXCHANGE_FILE }} artifact
uses: joutvhu/[email protected]
with:
name: ${{ env.EXCHANGE_FILE }}