-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (168 loc) · 5.78 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Build and Release Docker Image
env:
DOCKER_REGISTRY: nethermind.jfrog.io
REPO_DEV: angkor-docker-local-dev
REPO_STAGING: angkor-docker-local-staging
REPO_PROD: angkor-docker-local-prod
on:
push:
branches:
- main
workflow_dispatch:
inputs:
version:
type: choice
description: 'Environment to release to'
required: false
default: 'prod'
options:
- dev
- staging
- prod
permissions:
contents: write
id-token: write
jobs:
define_tag:
name: Define new Tag
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.bump_version.outputs.new_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get latest tag
id: get_latest_tag
run: |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0")
echo "latest_tag=${latest_tag}" >> $GITHUB_OUTPUT
- name: Validate semver
run: |
if ! [[ ${{ steps.get_latest_tag.outputs.latest_tag }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Latest tag does not follow semver standard"
exit 1
fi
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install commitizen
run: pip install --upgrade commitizen
# For the first time, you have to run cz bump manually
- name: Bump version
id: bump_version
run: |
new_version=$(cz bump --dry-run --yes | grep 'tag to create:' | awk '{print $4}')
echo "new_version=${new_version}" >> $GITHUB_OUTPUT
- name: Print new version
run: |
echo "New version: ${{ steps.bump_version.outputs.new_version }}"
build_docker_image:
name: Build and push Docker Image
runs-on: ubuntu-latest
needs: define_tag
env:
VERSION: ${{ needs.define_tag.outputs.tag }}
APP_NAME: ${{ github.event.repository.name }}
steps:
- name: Set REPO environment variable
run: |
if [[ "${{ github.event.inputs.version }}" == "dev" ]]; then
echo "REPO=${{ env.REPO_DEV }}" >> $GITHUB_ENV
elif [[ "${{ github.event.inputs.version }}" == "staging" ]]; then
echo "REPO=${{ env.REPO_STAGING }}" >> $GITHUB_ENV
else
echo "REPO=${{ env.REPO_PROD }}" >> $GITHUB_ENV
fi
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.23"
- name: Install abigen
run: make install-abigen
- name: Generate contract bindings
run: make generate
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to registry
run: |
docker login ${{ env.DOCKER_REGISTRY }} -u ${{ secrets.ARTIFACTORY_ANGKOR_USERNAME }} -p ${{ secrets.ARTIFACTORY_ANGKOR_TOKEN_DEVELOPER }}
- name: Build and Push
uses: docker/build-push-action@v6
with:
context: .
platforms: "linux/amd64"
push: true
file: Dockerfile
tags: |
${{ env.DOCKER_REGISTRY }}/${{ env.REPO }}/${{ env.APP_NAME }}:${{ env.VERSION }}
${{ env.DOCKER_REGISTRY }}/${{ env.REPO }}/${{ env.APP_NAME }}:latest
build-args: |
APP_NAME=${{ env.APP_NAME }}
VERSION=${{ env.VERSION }}
release:
runs-on: ubuntu-latest
name: "Bump version and create changelog with commitizen"
needs: define_tag
steps:
- name: Check out
uses: actions/checkout@v4
with:
token: "${{ secrets.GITHUB_TOKEN }}"
fetch-depth: 0
fetch-tags: true
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
git_push_gpgsign: true
trust_level: 5
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install commitizen
run: pip install --upgrade commitizen
- name: Bump Version and Create Changelog
id: cz
run: |
echo "Configure Git..."
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local pull.rebase true
git config --local commit.gpgsign true
git config --local tag.gpgsign false
export GPG_TTY=$(tty)
export GIT_EDITOR=true
echo "Bump version..."
cz --no-raise 21 bump --yes --changelog
# Get the new version from commitizen
new_version="$(cz version --project)"
current_branch="$(git branch --show-current)"
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
echo "Pull and push..."
git pull "$remote_repo" "$current_branch"
git push "$remote_repo" "HEAD:${current_branch}" --tags
# Output version number for next steps
echo "version=${new_version}" >> $GITHUB_OUTPUT
- name: Release
uses: softprops/action-gh-release@v1
with:
body_path: "CHANGELOG.md"
tag_name: v${{ steps.cz.outputs.version }}
draft: false
prerelease: true
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}