1111 # - .charts
1212 - LICENSE
1313 - README.md
14+ - build.sh
15+ - build.ps1
1416 pull_request :
1517 branches : [main]
1618 types : [opened, synchronize, reopened]
4749 - name : cargo build
4850 run : cargo build --release
4951
50- # TODO: could run cargo test here, etc...
51-
52- build_image :
53- if : false # debug disable
54- runs-on : ubuntu-latest
55- needs : build_app
56-
57- # https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/
58- # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
59- permissions :
60- packages : write # for pushing container image
61-
62- env :
63- REGISTRY : ghcr.io
64- # REPOSITORY: Note: set dynamically, i.e. github.repository_owner+IMAGE_NAME
65- GIT_REPO : ${{ github.repository }}
66- GIT_TAG : ${{ needs.build_app.outputs.SemVer }}
67- GIT_BRANCH : ${{ github.ref }}
68- GIT_COMMIT : ${{ github.sha }}
69-
70- steps :
71-
72- - uses : actions/checkout@v3
73- with :
74- fetch-depth : 0
75-
76- - name : set vars (1 of 2)
77- run : echo "REPOSITORY=${{ github.repository_owner }}/$IMAGE_NAME" >> $GITHUB_ENV
78-
79- - name : set vars (2 of 2)
80- if : github.ref != 'refs/heads/main' # non-default branch has a more verbose SemVer which we overwrite
81- run : echo "GIT_TAG=dev" >> $GITHUB_ENV
82-
52+ # TODO: enable other ci processes here
8353 - name : image:base
8454 run : docker build --platform linux/amd64 -t image:base . --target base
8555 if : false # debug
@@ -118,10 +88,40 @@ jobs:
11888 # run: docker run --rm --name clippy image:build cargo test
11989 # if: always()
12090
91+ build_image :
92+ runs-on : ubuntu-latest
93+ needs : build_app
94+
95+ # https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/
96+ # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
97+ permissions :
98+ packages : write # for pushing container image
99+
100+ env :
101+ REGISTRY : ghcr.io
102+ # REPOSITORY: Note: set dynamically, i.e. github.repository_owner+IMAGE_NAME
103+ GIT_REPO : ${{ github.repository }}
104+ GIT_TAG : ${{ needs.build_app.outputs.SemVer }}
105+ GIT_BRANCH : ${{ github.ref }}
106+ GIT_COMMIT : ${{ github.sha }}
107+
108+ steps :
109+ - uses : actions/checkout@v3
110+ with :
111+ fetch-depth : 0
112+
113+ - name : set vars (1 of 2)
114+ run : echo "REPOSITORY=${{ github.repository_owner }}/$IMAGE_NAME" >> $GITHUB_ENV
115+
116+ - name : set vars (2 of 2)
117+ if : github.ref != 'refs/heads/main' # non-default branch use a simplistic SemVer
118+ run : echo "GIT_TAG=dev" >> $GITHUB_ENV
119+
121120 - name : docker login ${{ env.REGISTRY }}
122121 run : echo "${{ secrets.GITHUB_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin
123122
124- - name : docker buildx build
123+ - name : docker buildx build/push
124+ if : github.ref == 'refs/heads/main'
125125 run : |
126126 docker buildx create --name multiarchtest --use
127127 docker buildx build \
@@ -139,4 +139,103 @@ jobs:
139139 --platform linux/amd64,linux/arm64,linux/arm/v7 \
140140 --pull \
141141 --push \
142- .
142+ .
143+
144+ - name : docker buildx build/push (dev)
145+ if : github.ref != 'refs/heads/main'
146+ run : |
147+ docker buildx create --name multiarchtest --use
148+ docker buildx build \
149+ -t $REGISTRY/$REPOSITORY:$GIT_TAG \
150+ --label "GITHUB_RUN_ID=${{ github.run_id }}" \
151+ --label "IMAGE_NAME=$IMAGE_NAME" \
152+ --build-arg GIT_REPO=$GIT_REPO \
153+ --build-arg GIT_TAG=$GIT_TAG \
154+ --build-arg GIT_BRANCH=$GIT_BRANCH \
155+ --build-arg GIT_COMMIT=$GIT_COMMIT \
156+ --build-arg GITHUB_WORKFLOW=${{ github.workflow }} \
157+ --build-arg GITHUB_RUN_ID=${{ github.run_id }} \
158+ --build-arg GITHUB_RUN_NUMBER=${{ github.run_number }} \
159+ --platform linux/amd64,linux/arm64,linux/arm/v7 \
160+ --pull \
161+ --push \
162+ .
163+
164+ push_chart :
165+ runs-on : ubuntu-latest
166+ needs : [build_app, build_image]
167+ if : github.ref == 'refs/heads/main'
168+
169+ permissions :
170+ packages : write # for pushing helm package
171+ contents : write # for creating releases/tags
172+
173+ env :
174+ REGISTRY : ghcr.io
175+ # REPOSITORY: Note: set dynamically, i.e. github.repository_owner+IMAGE_NAME
176+ GIT_TAG : ${{ needs.build_app.outputs.SemVer }}
177+ HELM_EXPERIMENTAL_OCI : 1
178+ HELM_VERSION_TO_INSTALL : 3.9.2 # Note: keep this version in sync inside the devcontainer
179+
180+ steps :
181+ - uses : actions/checkout@v3
182+ with :
183+ fetch-depth : 0 # Note: shallow clone may break git tag & ct lint...
184+
185+ - name : set vars
186+ run : echo "REPOSITORY=${{ github.repository_owner }}/charts/$IMAGE_NAME" >> $GITHUB_ENV
187+
188+ - name : install helm
189+ uses : azure/setup-helm@v3
190+ with :
191+ version : ${{ env.HELM_VERSION_TO_INSTALL }}
192+
193+ - name : helm registry login
194+ run : |
195+ echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ${REGISTRY}/${REPOSITORY} --username ${{ github.repository_owner }} --password-stdin
196+
197+ - uses : actions/setup-python@v4
198+ with :
199+ python-version : 3.7
200+ if : false # not implemented/working yet
201+
202+ - name : chart-testing (setup)
203+ uses : helm/chart-testing-action@v2
204+ if : false # not implemented/working yet
205+
206+ - name : chart-testing (run list-changed)
207+ id : list-changed
208+ run : |
209+ changed=$(ct list-changed --target-branch main)
210+ if [[ -n "$changed" ]]; then
211+ echo "::set-output name=changed::true"
212+ fi
213+ if : false # not implemented/working yet
214+
215+ - name : chart-testing (run lint)
216+ run : ct lint
217+ if : false # not implemented/working yet
218+
219+ - name : create kind cluster
220+ uses : helm/kind-action@v1
221+ # if: steps.list-changed.outputs.changed == 'true'
222+ if : false # not implemented/working yet
223+
224+ - name : chart-testing (run install)
225+ run : ct install
226+ if : false # not implemented/working yet
227+
228+ - name : helm package
229+ run : |
230+ helm package ${{ github.workspace }}/charts/$IMAGE_NAME/ --destination ${{ github.workspace }}/artifacts/ --app-version ${{ env.GIT_TAG }}
231+ if : false # not implemented/working yet
232+
233+ - name : helm push
234+ run : |
235+ helm push ${{ github.workspace }}/artifacts/$IMAGE_NAME-0.1.0.tgz oci://ghcr.io/${{ github.repository_owner }}
236+ if : false # not implemented/working yet, need to change the chart version in filename
237+
238+ release :
239+ needs : [build_app, build_image, push_chart]
240+ if : github.ref == 'refs/heads/main'
241+ uses : f2calv/gha-workflows/.github/workflows/gha-release-versioning.yml@v1
0 commit comments