-
Notifications
You must be signed in to change notification settings - Fork 5
120 lines (108 loc) · 4.23 KB
/
stage-3-build.yaml
File metadata and controls
120 lines (108 loc) · 4.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
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
name: 'Build stage'
on:
workflow_call:
inputs:
build_datetime:
description: 'Build datetime, set by the CI/CD pipeline workflow'
required: true
type: string
build_timestamp:
description: 'Build timestamp, set by the CI/CD pipeline workflow'
required: true
type: string
build_epoch:
description: 'Build epoch, set by the CI/CD pipeline workflow'
required: true
type: string
nodejs_version:
description: 'Node.js version, set by the CI/CD pipeline workflow'
required: true
type: string
python_version:
description: 'Python version, set by the CI/CD pipeline workflow'
required: true
type: string
terraform_version:
description: 'Terraform version, set by the CI/CD pipeline workflow'
required: true
type: string
version:
description: 'Version of the software, set by the CI/CD pipeline workflow'
required: true
type: string
commit_sha:
description: 'Commit sha of the docker image'
required: true
type: string
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DOCKER_METADATA_PR_HEAD_SHA: true
REPOSITORY_LOWERCASE: nhsdigital/dtos-manage-breast-screening
jobs:
build:
name: 'Build'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: 'Checkout code'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Log in to the Container registry
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # 4.0.0
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag
type=raw,value=${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '{{branch}}' }}
type=raw,value=${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || '' }}
type=sha,format=long,prefix=git-sha-
- name: Print commit SHA
env:
COMMIT_SHA: ${{ inputs.commit_sha }}
run: echo "Commit SHA is ${COMMIT_SHA}"
- name: Set branch environment variable (push)
if: github.event_name == 'push'
shell: bash
env:
GITHUB_REF_VALUE: ${{ github.ref }}
run: echo "GIT_BRANCH=${GITHUB_REF_VALUE##*/}" >> $GITHUB_ENV # GIT_BRANCH will be main for refs/heads/main
- name: Set branch environment variable (pull_request)
if: github.event_name == 'pull_request'
shell: bash
env:
GITHUB_HEAD_REF_VALUE: ${{ github.head_ref }}
run: echo "GIT_BRANCH=${GITHUB_HEAD_REF_VALUE##*/}" >> $GITHUB_ENV
- name: Build and push Docker image
id: push
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
COMMIT_SHA=${{ inputs.commit_sha }}
cache-from: |
type=registry,ref=${{ env.REGISTRY }}/${{ env.REPOSITORY_LOWERCASE }}:cache-${{ env.GIT_BRANCH }}
type=registry,ref=${{ env.REGISTRY }}/${{ env.REPOSITORY_LOWERCASE }}:cache-main
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.REPOSITORY_LOWERCASE }}:cache-${{ env.GIT_BRANCH }},mode=max
- name: Generate artifact attestation
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true