-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (109 loc) · 3.49 KB
/
pull_request.yaml
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
name: NPM Build and Push Docker Image On PR
on:
pull_request_target:
types:
- closed
branches:
- 'development'
- 'rc/**'
- 'hotfix/**'
workflow_dispatch:
env:
GITHUB_REGISTRY: ghcr.io
DOCKER_IMAGE_NAME: <docker_image_name>
GITHUB_NAMESPACE: valtimo-cloud
jobs:
if_merged:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- run: |
echo "The PR was merged"
build:
runs-on: ubuntu-latest
needs: [ if_merged ]
outputs:
tagToDeploy: ${{ steps.prep.outputs.image_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js version
uses: actions/setup-node@v2
with:
node-version: "16.x"
- name: 'Generate unique docker tag to deploy'
id: prep
run: |
branch=${GITHUB_REF##*/}
sha=${GITHUB_SHA::8}
ts=$(date +'%Y%m%d%H%M')
echo "image_tag=${branch}-${ts}-${sha}" >> "$GITHUB_OUTPUT"
- name: NPM install and build
run: |
npm install
npm run build
- name: Build artifacts
run: ./gradlew build
- name: Archive dist folder
uses: actions/upload-artifact@v4
with:
name: valtimo-frontend-dist
path: deployment/
deploy:
runs-on: ubuntu-latest
needs: [build]
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout code
uses: actions/[email protected]
with:
fetch-depth: 1
- name: Install Cosign
uses: sigstore/[email protected]
- name: Set up QEMU
uses: docker/[email protected]
- name: Set up Docker Buildx
uses: docker/[email protected]
- name: Download dist artifact
uses: actions/download-artifact@v4
with:
name: valtimo-frontend-dist
path: deployment/
- name: 'Login to github packages'
uses: docker/login-action@v1
with:
registry: ${{ env.GITHUB_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: docker_meta
uses: docker/[email protected]
with:
images: ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_NAMESPACE }}/${{ env.DOCKER_IMAGE_NAME }}
tags: type=raw,value=${{ needs.build.outputs.tagToDeploy }}
- name: Build and push Docker image
uses: docker/[email protected]
id: build-and-push
with:
file: Dockerfile
context: .
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
- name: Sign the images with GitHub OIDC Token
env:
DIGEST: ${{ steps.build-and-push.outputs.digest }}
TAGS: ${{ steps.docker_meta.outputs.tags }}
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
cosign sign --yes ${images}
- name: Verify the images
run: |
branch=${GITHUB_REF##*/}
cosign verify ${{ env.GITHUB_REGISTRY }}/${{ env.GITHUB_NAMESPACE }}/${{ env.DOCKER_IMAGE_NAME }}:${{ needs.build.outputs.tagToDeploy }} \
--certificate-identity https://github.com/${{ env.GITHUB_NAMESPACE }}/${{ env.DOCKER_IMAGE_NAME }}/.github/workflows/pull_request.yaml@refs/heads/${branch} \
--certificate-oidc-issuer https://token.actions.githubusercontent.com | jq