-
Notifications
You must be signed in to change notification settings - Fork 2
153 lines (130 loc) · 4.98 KB
/
release.yml
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
name: release
on:
push:
branches:
- master
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
jobs:
release-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: 20
cache: "npm"
- name: Install dependencies
run: npm ci
env:
SKIP_BUILD: true
- name: Lint
run: npm run lint -- --no-fix
release-semantic:
needs: release-test
runs-on: ubuntu-latest
outputs:
published: ${{ steps.release.outputs.published }}
release-version: ${{ steps.release.outputs.release-version }}
release-version-major: ${{ steps.release.outputs.release-version-major }}
release-version-minor: ${{ steps.release.outputs.release-version-minor }}
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup Node.js
uses: actions/[email protected]
with:
node-version: 20
cache: "npm"
- name: Install dependencies
run: npm ci
env:
SKIP_BUILD: true
- name: Semantic release
id: release
uses: ahmadnassri/[email protected]
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
npm_config_unsafe_perm: true
release-alias:
needs: release-semantic
if: needs.release-semantic.outputs.published == 'true'
runs-on: ubuntu-latest
strategy:
matrix:
tag:
- v${{ needs.release-semantic.outputs.release-version-major }}
- v${{ needs.release-semantic.outputs.release-version-major }}.${{ needs.release-semantic.outputs.release-version-minor }}
steps:
- name: Recreate tag
uses: actions/[email protected]
with:
script: |
const tag = 'tags/${{ matrix.tag }}';
const repo = {
owner: context.repo.owner,
repo: context.repo.repo
};
await github.rest.git.deleteRef({ ...repo, ref: tag }).catch(() => {});
await github.rest.git.createRef({ ...repo, ref: `refs/${tag}` , sha: process.env.GITHUB_SHA });
release-docker:
needs: release-semantic
if: needs.release-semantic.outputs.published == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Repo metadata
id: repo
uses: actions/[email protected]
with:
script: |
const repo = await github.rest.repos.get(context.repo)
return repo.data
- name: Prepare
id: prep
run: |
echo ::set-output name=docker-image::${{ github.event.repository.full_name }}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up Docker Buildx
id: buildx
uses: docker/[email protected]
with:
version: latest
- name: Login to DockerHub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker-build
uses: docker/[email protected]
with:
push: true
builder: ${{ steps.buildx.outputs.name }}
context: .
tags: |
${{ steps.prep.outputs.docker-image }}:latest
${{ steps.prep.outputs.docker-image }}:${{ needs.release-semantic.outputs.release-version }}
${{ steps.prep.outputs.docker-image }}:${{ needs.release-semantic.outputs.release-version-major }}.${{ needs.release-semantic.outputs.release-version-minor }}
${{ steps.prep.outputs.docker-image }}:${{ needs.release-semantic.outputs.release-version-major }}
labels: |
org.opencontainers.image.title=${{ fromJson(steps.repo.outputs.result).name }}
org.opencontainers.image.description=${{ fromJson(steps.repo.outputs.result).description }}
org.opencontainers.image.url=${{ fromJson(steps.repo.outputs.result).html_url }}
org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).clone_url }}
org.opencontainers.image.version=${{ needs.release-semantic.outputs.release-version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Update repo description
uses: peter-evans/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: ${{ github.event.repository.full_name }}