forked from istio-ecosystem/fortsa
-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (115 loc) · 4.37 KB
/
release.yml
File metadata and controls
132 lines (115 loc) · 4.37 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
name: Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to create (e.g. v1.0.0, v2.3.4-rc1)'
required: true
type: string
permissions:
contents: write
packages: write
jobs:
release:
name: Build and Release
runs-on: ubuntu-latest
steps:
- name: Validate tag
if: github.event_name == 'workflow_dispatch'
run: |
if ! [[ "${{ inputs.tag }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Tag must match pattern v[0-9]+.[0-9]+.[0-9]+* (e.g. v1.0.0, v2.3.4-rc1)"
exit 1
fi
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.ref }}
fetch-depth: 0
fetch-tags: true
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Install Helm
uses: azure/setup-helm@v4
- name: Install chart-releaser
run: |
CR_VERSION="v1.8.1"
ARCH=$(uname -m)
case "$ARCH" in
x86_64) CR_ARCH="linux_amd64" ;;
aarch64|arm64) CR_ARCH="linux_arm64" ;;
*) echo "Unsupported arch: $ARCH"; exit 1 ;;
esac
curl -sSLo cr.tar.gz "https://github.com/helm/chart-releaser/releases/download/${CR_VERSION}/chart-releaser_${CR_VERSION#v}_${CR_ARCH}.tar.gz"
tar -xzf cr.tar.gz -C /usr/local/bin
rm cr.tar.gz
cr version
- name: Configure git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute version and release type
id: compute_version
run: |
set -e
git fetch origin
TAG_NAME="${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}"
COMMIT=$(git rev-parse "HEAD^{commit}")
BRANCHES=$(git branch -r --contains "$COMMIT" | sed 's|^[[:space:]]*origin/||' | grep -v 'HEAD')
if echo "$BRANCHES" | grep -qx 'main'; then
IMAGE_TAG="${TAG_NAME#v}"
PRERELEASE="false"
MAKE_LATEST="true"
else
SHORT_SHA=$(git rev-parse --short=7 "$COMMIT")
IMAGE_TAG="${TAG_NAME#v}-${SHORT_SHA}"
PRERELEASE="true"
MAKE_LATEST="false"
fi
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_OUTPUT
echo "MAKE_LATEST=$MAKE_LATEST" >> $GITHUB_OUTPUT
- name: Build and push application image
run: |
make docker-buildx IMAGE_TAG_BASE="ghcr.io/${{ github.repository }}" VERSION="${{ steps.compute_version.outputs.IMAGE_TAG }}"
- name: Build and push helm chart
run: |
make helm-build IMAGE_TAG_BASE="ghcr.io/${{ github.repository }}" VERSION="${{ steps.compute_version.outputs.IMAGE_TAG }}"
helm push ./build/fortsa-helm-chart-${{ steps.compute_version.outputs.IMAGE_TAG }}.tgz oci://ghcr.io/${{ github.repository_owner }}/helm
- name: Create release and upload Helm chart
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.compute_version.outputs.IMAGE_TAG }}
name: v${{ steps.compute_version.outputs.IMAGE_TAG }}
make_latest: ${{ steps.compute_version.outputs.MAKE_LATEST }}
prerelease: ${{ steps.compute_version.outputs.PRERELEASE }}
files: ./build/fortsa-helm-chart-${{ steps.compute_version.outputs.IMAGE_TAG }}.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update chart index on gh-pages
run: |
mkdir -p .cr-index
REPO_NAME="${GITHUB_REPOSITORY#*/}"
cr index \
-o "${{ github.repository_owner }}" \
-r "$REPO_NAME" \
--config .cr.yaml \
--release-name-template "v{{ .Version }}" \
--push
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Set release to draft
run: gh release edit "v${{ steps.compute_version.outputs.IMAGE_TAG }}" --draft
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}