Skip to content

Commit 4d77213

Browse files
committed
Add task-runner build to ci
1 parent cab098d commit 4d77213

File tree

1 file changed

+97
-6
lines changed

1 file changed

+97
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 97 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919
env:
2020
ormolu_version: 0.5.2.0
2121
is_published_build: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/staging') }}
22+
is_task_build: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/heads/task-') }}
2223
exe_cache_prefix: share-ci-exe
2324
share_local_bin: share-api
2425

@@ -56,7 +57,7 @@ jobs:
5657
&& github.event.pull_request.base.repo.full_name == github.event.pull_request.head.repo.full_name
5758
with:
5859
commit_message: automatically run ormolu
59-
build-exe:
60+
build-exes:
6061
name: Build share-api executable
6162
runs-on: ubuntu-24.04
6263
steps:
@@ -83,12 +84,19 @@ jobs:
8384
--copy-bins \
8485
${{ (env.is_published_build && '--ghc-options -O2') || '--fast' }}
8586
86-
- name: Save exes for docker build
87+
- name: Save exes for share-api docker build
8788
uses: actions/upload-artifact@v4
8889
with:
8990
name: share-api-exe
9091
path: ${{env.share_local_bin}}
9192

93+
- name: Save exes for share-task-runner docker build
94+
if: env.is_task_build
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: share-task-runner-exe
98+
path: ${{env.share_local_bin}}
99+
92100
- name: save stack caches
93101
if: |
94102
!cancelled()
@@ -97,11 +105,11 @@ jobs:
97105
with:
98106
cache-prefix: ${{env.exe_cache_prefix}}
99107

100-
# A separate job for docker build because it requires elevated github token permissions.
101-
docker-build:
108+
# Separate jobs for the docker builds because they requires elevated github token permissions.
109+
share-api-docker-build:
102110
env:
103111
container_registry: ghcr.io
104-
docker_image_name: ${{ github.repository }}
112+
docker_image_name: share-api
105113
needs: [build-exe]
106114
runs-on: ubuntu-24.04
107115
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
@@ -158,6 +166,7 @@ jobs:
158166
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
159167
with:
160168
context: ./docker/
169+
file: ./docker/share-api.Dockerfile
161170
push: ${{ env.is_published_build }}
162171
tags: ${{ steps.meta.outputs.tags }}
163172
labels: ${{ steps.meta.outputs.labels }}
@@ -184,9 +193,91 @@ jobs:
184193
subject-digest: ${{ steps.push.outputs.digest }}
185194
push-to-registry: true
186195

196+
# Separate jobs for the docker builds because they requires elevated github token permissions.
197+
share-task-runner-docker-build:
198+
if: env.is_task_build
199+
env:
200+
container_registry: ghcr.io
201+
docker_image_name: share-task-runner
202+
needs: [build-exes]
203+
runs-on: ubuntu-24.04
204+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
205+
permissions:
206+
contents: read
207+
# Allow uploading the docker image to the container registry
208+
packages: write
209+
# Allow creating and updating the artifact attestation
210+
attestations: write
211+
# Required to get user information for building attestations
212+
id-token: write
213+
214+
steps:
215+
- uses: actions/checkout@v4
216+
with:
217+
# Don't need unison submodule for docker image build
218+
submodules: false
219+
220+
# Downloads the artifact that contains the share-api-exe from the previous job.
221+
- uses: actions/download-artifact@v4
222+
with:
223+
name: share-task-runner-exe
224+
path: ./docker/tmp/
225+
226+
# Configure Docker's builder,
227+
# This seems necessary to support docker cache layers.
228+
- name: Setup Docker buildx
229+
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0
230+
231+
232+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
233+
- name: Log in to the Container registry
234+
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
235+
with:
236+
registry: ${{ env.container_registry }}
237+
username: ${{ github.actor }}
238+
password: ${{ secrets.GITHUB_TOKEN }}
239+
240+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
241+
- name: Extract metadata (tags, labels) for Docker
242+
id: meta
243+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
244+
with:
245+
images: ${{ env.container_registry }}/${{ env.docker_image_name }}
246+
tags: |
247+
type=sha,priority=1000,format=short,prefix={{branch}}_{{date 'YYYY-MM-DD-HH-mm'}}_gitref-
248+
type=sha,format=long
249+
250+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
251+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
252+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
253+
- name: Build and push Docker image
254+
id: push
255+
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
256+
with:
257+
context: ./docker/
258+
file: ./docker/task-runner.Dockerfile
259+
push: true
260+
tags: ${{ steps.meta.outputs.tags }}
261+
labels: ${{ steps.meta.outputs.labels }}
262+
# Use github actions cache for docker image layers
263+
cache-from: type=gha
264+
cache-to: type=gha,mode=max
265+
build-args: |
266+
SHARE_COMMIT=${{ github.sha }}
267+
# Save image locally for use in tests even if we don't push it.
268+
outputs: type=docker,dest=/tmp/share-docker-image.tar # export docker image
269+
270+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see "[AUTOTITLE](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)."
271+
- name: Generate artifact attestation
272+
uses: actions/[email protected]
273+
with:
274+
subject-name: ${{ env.container_registry }}/${{ env.docker_image_name}}
275+
subject-digest: ${{ steps.push.outputs.digest }}
276+
push-to-registry: true
277+
187278
# A separate job for docker build because it requires elevated github token permissions.
188279
transcript-tests:
189-
needs: [build-exe, docker-build]
280+
needs: [build-exes, share-api-docker-build]
190281
runs-on: ubuntu-24.04
191282

192283
steps:

0 commit comments

Comments
 (0)