forked from kubernetes-sigs/cluster-api
-
Notifications
You must be signed in to change notification settings - Fork 1
133 lines (130 loc) · 5.38 KB
/
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
name: Create Release
on:
push:
branches:
- main
paths:
- 'CHANGELOG/*.md'
permissions:
contents: write # Allow to push a tag, create a release branch and publish a draft release.
jobs:
push_release_tags:
runs-on: ubuntu-latest
outputs:
release_tag: ${{ steps.release-version.outputs.release_version }}
steps:
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@d6babd6899969df1a11d14c368283ea4436bca78 # tag=v44.5.2
- name: Get release version
id: release-version
run: |
if [[ ${{ steps.changed-files.outputs.all_changed_files_count }} != 1 ]]; then
echo "1 release notes file should be changed to create a release tag, found ${{ steps.changed-files.outputs.all_changed_files_count }}"
exit 1
fi
for changed_file in ${{ steps.changed-files.outputs.all_changed_files }}; do
export RELEASE_VERSION=$(echo "${changed_file}" | grep -oP '(?<=/)[^/]+(?=\.md)')
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_OUTPUT
if [[ "$RELEASE_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
echo "Valid semver: $RELEASE_VERSION"
else
echo "Invalid semver: $RELEASE_VERSION"
exit 1
fi
done
- name: Determine the release branch to use
run: |
if [[ $RELEASE_VERSION =~ beta ]] || [[ $RELEASE_VERSION =~ alpha ]]; then
export RELEASE_BRANCH=main
echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV
echo "This is a beta or alpha release, will use release branch $RELEASE_BRANCH"
else
export RELEASE_BRANCH=d2iq/release-$(echo $RELEASE_VERSION | sed -E 's/^v([0-9]+)\.([0-9]+)\.([0-9]+).*$/\1.\2.\3/')
echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV
echo "This is not a beta or alpha release, will use release branch $RELEASE_BRANCH"
fi
- name: Create or checkout release branch
run: |
if git show-ref --verify --quiet "refs/remotes/origin/$RELEASE_BRANCH"; then
echo "Branch $RELEASE_BRANCH already exists"
git checkout "$RELEASE_BRANCH"
else
git checkout -b "$RELEASE_BRANCH"
git push origin "$RELEASE_BRANCH"
echo "Created branch $RELEASE_BRANCH"
fi
- name: Validate tag does not already exist
run: |
if [[ $(git tag -l $RELEASE_VERSION) ]]; then
echo "Tag $RELEASE_VERSION already exists, exiting"
exit 1
fi
- name: Create Release Tag
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git tag -a ${RELEASE_VERSION} -m ${RELEASE_VERSION}
git tag test/${RELEASE_VERSION}
git push origin ${RELEASE_VERSION}
git push origin test/${RELEASE_VERSION}
echo "Created tags $RELEASE_VERSION and test/${RELEASE_VERSION}"
release:
name: create draft release
runs-on: ubuntu-latest
needs: push_release_tags
permissions:
contents: write
packages: write
steps:
- name: Set env
run: |
echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV
echo "REGISTRY=${REGISTRY}" >> $GITHUB_ENV
echo "PROD_REGISTRY=${REGISTRY}" >> $GITHUB_ENV
echo "STAGING_REGISTRY=${REGISTRY}" >> $GITHUB_ENV
echo "TAG=${RELEASE_TAG}" >> $GITHUB_ENV
echo "PULL_POLICY=IfNotPresent" >> $GITHUB_ENV
env:
RELEASE_TAG: ${{needs.push_release_tags.outputs.release_tag}}
REGISTRY: ghcr.io/mesosphere
- name: checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7
with:
fetch-depth: 0
ref: ${{ env.RELEASE_TAG }}
- name: Calculate go version
run: echo "go_version=$(make go-version)" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # tag=v5.0.1
with:
go-version: ${{ env.go_version }}
- name: generate release artifacts
run: |
make release
- name: get release notes
run: |
curl -L "https://raw.githubusercontent.com/${{ github.repository }}/main/CHANGELOG/${{ env.RELEASE_TAG }}.md" \
-o "${{ env.RELEASE_TAG }}.md"
- name: Release
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # tag=v2.0.5
with:
draft: true
files: out/*
body_path: ${{ env.RELEASE_TAG }}.md
tag_name: ${{ env.RELEASE_TAG }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push docker images
run: |
make ALL_ARCH="amd64 arm64" docker-build-all
make ALL_ARCH="amd64 arm64" docker-push-all