-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (177 loc) · 5.74 KB
/
build.yaml
File metadata and controls
183 lines (177 loc) · 5.74 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Build
on:
pull_request_target:
branches:
- master
push:
branches:
- master
jobs:
configure:
name: Configure
runs-on: ubuntu-22.04
timeout-minutes: 4
outputs:
commit-sha: ${{ env.COMMIT_SHA }}
steps:
- name: Evaluate commit
run: |
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
echo "PR is #${{ github.event.number }}..."
echo "PR Head SHA is ${{ github.event.pull_request.head.sha }}..."
echo "COMMIT_SHA=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
else
echo "Head SHA is ${{ github.sha }}..."
echo "COMMIT_SHA=${{ github.sha }}" >> $GITHUB_ENV
fi
check:
name: Check
runs-on: ubuntu-22.04
needs:
- configure
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.configure.outputs.commit-sha }}
- name: Setup Node.js
uses: abinnovision/actions@setup-node-v1
- name: Install dependencies
run: yarn install --immutable
- name: Check
run: yarn run check
- name: Check Dependencies
run: |
yarn dedupe
git diff --exit-code --quiet yarn.lock || (echo "yarn.lock is not up to date, run 'yarn dedupe'" && exit 1)
build_test:
name: Build & Test
runs-on: ubuntu-22.04
needs:
- configure
- check
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.configure.outputs.commit-sha }}
- name: Setup Node.js
uses: abinnovision/actions@setup-node-v1
- name: Install dependencies
run: yarn install --immutable
- name: Build
run: yarn build
- name: Test
run: yarn run test
release:
name: Release
uses: abinnovision/workflows/.github/workflows/release-please.yaml@master
secrets: inherit
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
default-branch: master
needs:
- configure
build-image:
name: Build Image
runs-on: ubuntu-22.04
needs:
- configure
- build_test
- release
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
env:
DOCKER_REGISTRY: ghcr.io
permissions:
contents: "read"
packages: "write"
id-token: "write"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.configure.outputs.commit-sha }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build image name
run: |
REPOSITORY_NAME_SANITIZED=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]');
echo "DOCKER_IMAGE_NAME=ghcr.io/$REPOSITORY_NAME_SANITIZED" >> $GITHUB_ENV
- name: Extract version
run: |
echo PKG_VERSION=$(cat package.json | jq -r ".version") >> $GITHUB_ENV
- name: Extract Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE_NAME }}
tags: |
type=sha,enable=true
# Version tag is only needed for released versions.
type=semver,pattern={{version}},value=v${{ env.PKG_VERSION }},enable=${{ contains(fromJSON(needs.release.outputs.paths_released), '.') }}
# Extract metadata for Docker Hub.
# This is only needed for releases.
- name: Extract Metadata for Docker Hub
id: meta-dockerhub
uses: docker/metadata-action@v5
with:
images: abinnovision/github-workflow-dispatch-proxy
tags: |
type=semver,pattern={{version}},value=v${{ env.PKG_VERSION }},enable=${{ contains(fromJSON(needs.release.outputs.paths_released), '.') }}
- name: Container Registry Auth
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Login to Docker Hub only if a release is published.
- name: Login to Docker Hub
uses: docker/login-action@v3
if: contains(fromJSON(needs.release.outputs.paths_released), '.')
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v4
with:
context: "."
push: true
file: Dockerfile
labels: ${{ steps.meta.outputs.labels }}
tags: |
${{ steps.meta.outputs.tags }}
${{ steps.meta-dockerhub.outputs.tags }}
secrets: |
NPM_ABINNOVISION_AUTH_TOKEN=${{ github.token }}
cleanup-registry:
name: Cleanup Registry
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
permissions:
contents: "read"
packages: "write"
needs:
- build-image
steps:
- name: Prepare
run: |
echo "PACKAGE_NAME=$(echo "${GITHUB_REPOSITORY#*/}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Cleanup non-release images
uses: snok/container-retention-policy@v3.0.0
with:
account: abinnovision
token: ${{ secrets.GITHUB_TOKEN }}
image-names: ${{ env.PACKAGE_NAME }}
cut-off: 1w
keep-n-most-recent: 2
image-tags: "sha-*"
- name: Cleanup untagged images
uses: snok/container-retention-policy@v3.0.0
with:
account: abinnovision
token: ${{ secrets.GITHUB_TOKEN }}
image-names: ${{ env.PACKAGE_NAME }}
keep-n-most-recent: 0
tag-selection: "untagged"
cut-off: "1d"