forked from XGovFormBuilder/digital-form-builder
-
Notifications
You must be signed in to change notification settings - Fork 6
97 lines (88 loc) · 3.38 KB
/
Copy pathbuild.yml
File metadata and controls
97 lines (88 loc) · 3.38 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
92
93
94
95
96
97
name: build app
on:
workflow_call:
inputs:
app:
description: the app to build "designer", "runner" or "submitter"
required: true
type: string
publish:
description: Set to true to publish to GHCR. Defaults to false
type: boolean
required: false
semver:
description: The semantic version you wish to publish with
required: false
type: string
outputs:
tag:
description: tag used for docker caching
value: ${{ jobs.build-app.outputs.tag }}
hash:
description: hash used for docker caching
value: ${{ jobs.build-app.outputs.hash }}
jobs:
build-app:
if: ${{!contains(github.event.head_commit.message, 'chore(deps-dev)')}}
runs-on: ubuntu-latest
name: Docker build
outputs:
tag: ${{ steps.hashFile.outputs.tag }}
hash: ${{ steps.hashFile.outputs.hash }}
steps:
- uses: actions/checkout@v5
- name: Use Node.js
uses: actions/setup-node@v5
with:
node-version: "16.x"
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
- uses: actions/cache@v5
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{inputs.app}}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-${{inputs.app}}
fail-on-cache-miss: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
with:
buildkitd-config-inline: |
[registry."ghcr.io"]
- name: Login to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# The hash is a function of the Dockerfile and the yarn.lock Packages take up the bulk of the time during a docker build. The hash is used to cache the docker builds.
# As long as the yarn.lock and dockerfiles are the same, you will be able to share this cache with another commit/branch.
- id: hashFile
env:
HASH_TARGET: "${{inputs.app}}/Dockerfile"
run: |
echo "::set-output name=hash::${{hashFiles(env.HASH_TARGET, 'yarn.lock')}}"
echo "::set-output name=tag::ghcr.io/xgovformbuilder/cache-digital-form-builder-${{inputs.app}}:${{hashFiles(env.HASH_TARGET)}}"
- name: Build ${{inputs.app}}
if: ${{inputs.publish != true }}
uses: docker/build-push-action@v7
with:
file: ${{inputs.app}}/Dockerfile
push: false
context: .
tags: ${{ steps.hashFile.outputs.tag }}
- name: Build ${{inputs.app}} and push
if: ${{inputs.semver && inputs.publish == true }}
uses: docker/build-push-action@v7
with:
file: ${{inputs.app}}/Dockerfile
push: true
context: .
tags: |
ghcr.io/xgovformbuilder/digital-form-builder-${{inputs.app}}:${{inputs.semver}}
ghcr.io/xgovformbuilder/digital-form-builder-${{inputs.app}}:latest
build-args: |
LAST_TAG_GH=${{inputs.semver}}
LAST_COMMIT=${{github.sha}}