-
Notifications
You must be signed in to change notification settings - Fork 0
181 lines (176 loc) · 5.65 KB
/
create_release.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
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
name: Create Release
on:
workflow_dispatch:
inputs:
bumpVersion:
description: "Bump version"
required: true
default: patch
type: choice
options:
- skip
- patch
- minor
- major
env:
CARGO_TERM_COLOR: always
RUST_VERSION: 1.66.0
jobs:
prepare_version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.gv.outputs.version }}
steps:
- uses: actions/checkout@v3
- name: Check branch
run: |
if [[ ! `git branch --show-current` = 'master' ]] ; then
echo "Releases can only be created from the \`master\` branch" >&2
exit 1
fi
- name: Prepare branch
run: |
git fetch --tags
git checkout -b feature
- name: Bump version
if: inputs.bumpVersion != 'skip'
run: |
scripts/bump_version.py ${{ inputs.bumpVersion }} ${{ github.repository_owner }}
- name: Get version
id: gv
run: |
version=`scripts/get_version.py`
echo "version=$version" >> $GITHUB_OUTPUT
- name: Update lock file
if: inputs.bumpVersion != 'skip'
uses: actions-rs/cargo@v1
with:
command: update
args: --package signal-inspector-backend --package signal-inspector-frontend
- name: Create release branch
if: inputs.bumpVersion != 'skip'
id: crb
run: |
release_branch="release/v${VERSION}"
git checkout -b "$release_branch"
git \
-c author.name=${{ github.actor }} \
-c author.email=${{ github.actor }}@users.noreply.github.com \
-c committer.name=Github \
-c committer.email=noreply@github.com \
commit -a -m "Prepare release v${VERSION}"
git push --set-upstream origin "$release_branch"
echo "release_branch=$release_branch" >> $GITHUB_OUTPUT
env:
VERSION: ${{ steps.gv.outputs.version }}
- name: Create pull request
if: inputs.bumpVersion != 'skip'
id: cpr
uses: octokit/request-action@v2.x
with:
route: POST /repos/${{ github.repository }}/pulls
title: Release v${{ env.VERSION }}
body: Bump to version v${{ env.VERSION }}.
base: master
head: ${{ env.RELEASE_BRANCH }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_BRANCH: ${{ steps.crb.outputs.release_branch }}
VERSION: ${{ steps.gv.outputs.version }}
- name: Get pull request number
if: inputs.bumpVersion != 'skip'
id: gprn
uses: sergeysova/jq-action@v2
with:
cmd: echo '${{ steps.cpr.outputs.data }}' | jq .number -r
env:
JSON_DATA: ${{ steps.cpr.outputs.data }}
- name: Merge pull request
if: inputs.bumpVersion != 'skip'
uses: octokit/request-action@v2.x
with:
route: PUT /repos/${{ github.repository }}/pulls/${{ env.PULL_NUMBER }}/merge
commit_title: Prepare release v${{ env.VERSION }} (#${{ env.PULL_NUMBER }})
merge_method: squash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_NUMBER: ${{ steps.gprn.outputs.value }}
VERSION: ${{ steps.gv.outputs.version }}
build:
needs: prepare_version
env:
VERSION: ${{ needs.prepare_version.outputs.version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: master
- name: Setup Docker
uses: docker/setup-buildx-action@v1
- name: Login to Github Container registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
- name: Build and push image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/signal-inspector-backend:${{ env.VERSION }}
cache-from: type=gha
cache-to: type=gha,mode=max
create_release:
needs: [prepare_version, build]
env:
VERSION: ${{ needs.prepare_version.outputs.version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: master
- name: Get changelog
id: gcb
run: |
changelog_body=`scripts/get_changelog.py`
echo "changelog_body=${changelog_body}" >> $GITHUB_OUTPUT
- name: Create release draft
id: crd
uses: octokit/request-action@v2.x
with:
route: POST /repos/${{ github.repository }}/releases
tag_name: v${{ env.VERSION }}
target_commitish: master
name: v${{ env.VERSION }}
body: |-
${{ steps.gcb.outputs.changelog_body }}
draft: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get release number
id: grn
uses: sergeysova/jq-action@v2
with:
cmd: echo '${{ steps.crd.outputs.data }}' | jq .id -r
env:
JSON_DATA: ${{ steps.cpr.outputs.data }}
- name: Upload artifact
run: |
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Content-Type: text/plain" \
--data-binary @hocfile.yaml \
https://uploads.github.com/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets?name=hocfile.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_ID: ${{ steps.grn.outputs.value }}
- name: Publish release
uses: octokit/request-action@v2.x
with:
route: PATCH /repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}
draft: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_ID: ${{ steps.grn.outputs.value }}