-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (124 loc) · 4.06 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
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 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: 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"
steps:
- name: Check out
uses: actions/checkout@v4
with:
token: "${{ secrets.GITHUB_TOKEN }}"
fetch-depth: 0
- name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
changelog_increment_filename: CHANGELOG.md
- name: Release
uses: softprops/action-gh-release@v1
with:
body_path: "CHANGELOG.md"
tag_name: ${{ env.REVISION }}
draft: false
prerelease: true
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}