This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
166 lines (147 loc) · 5.85 KB
/
push.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
name: push
on:
push:
branches:
- main
tags:
- v*
jobs:
build:
runs-on: ubuntu-latest
name: build
permissions:
contents: write
packages: write
steps:
- name: set repo name
shell: bash
run: |
echo "REPOSITORY_NAME=$(basename $GITHUB_REPOSITORY)" >> $GITHUB_ENV
- name: Check out code
uses: actions/checkout@v2
- name: Download operator sdk
shell: bash
env:
RELEASE_VERSION: v1.9.0
run: |
curl -LO https://github.com/operator-framework/operator-sdk/releases/download/${RELEASE_VERSION}/operator-sdk_linux_amd64
chmod +x operator-sdk_linux_amd64
mkdir ${HOME}/bin
mv operator-sdk_linux_amd64 ${HOME}/bin/operator-sdk
echo "${HOME}/bin" >> $GITHUB_PATH
- name: Get the version for tags
id: get_version1
if: "startsWith(github.ref, 'refs/tags')"
shell: bash
run: |
echo "OPERATOR_IMAGE_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
echo "BUNDLE_IMAGE_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
export TAG=${GITHUB_REF/refs\/tags\//}
echo "BUNDLE_VERSION=${TAG:1}" >> $GITHUB_ENV
export SEMVER_COMPLIANT=$(echo ${TAG:1} | egrep '^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$')
if [ -z "$SEMVER_COMPLIANT" ]; then echo "invalid semver tag ${GITHUB_REF/refs\/tags\//}"; exit 1; fi
- name: Get the version for merge
id: get_version2
if: "! startsWith(github.ref, 'refs/tags')"
shell: bash
run: |
echo "OPERATOR_IMAGE_TAG=latest" >> $GITHUB_ENV
echo "BUNDLE_IMAGE_TAG=v0.0.1" >> $GITHUB_ENV
echo "BUNDLE_VERSION=0.0.1" >> $GITHUB_ENV
- name: build bundle
shell: bash
run: |
make bundle IMG=ghcr.io/${{ github.repository_owner }}/$(basename $GITHUB_REPOSITORY):${OPERATOR_IMAGE_TAG} VERSION=${BUNDLE_VERSION} DEFAULT_CHANNEL=alpha
- name: verify bundle
shell: bash
run: operator-sdk bundle validate ./bundle --select-optional name=operatorhub
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
- name: "Build and Push Operator Image"
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64,linux/ppc64le
push: true
tags: "ghcr.io/${{ github.repository_owner }}/${{ env.REPOSITORY_NAME }}:${{ env.OPERATOR_IMAGE_TAG }}"
- name: "Build and Push Bundle Image"
uses: docker/build-push-action@v2
with:
context: .
file: ./bundle.Dockerfile
platforms: linux/amd64,linux/arm64,linux/ppc64le
push: true
tags: "ghcr.io/${{ github.repository_owner }}/${{ env.REPOSITORY_NAME }}-bundle:${{ env.BUNDLE_IMAGE_TAG }}"
- name: "Verify bundle image"
shell: bash
run: operator-sdk bundle validate ghcr.io/${{ github.repository_owner }}/$(basename $GITHUB_REPOSITORY)-bundle:${BUNDLE_IMAGE_TAG} --select-optional name=operatorhub
- name: process bundle for disconnected support
uses: redhat-cop/github-actions/disconnected-csv@master
with:
CSV_FILE: bundle/manifests/${{ env.REPOSITORY_NAME }}.clusterserviceversion.yaml
TAGS_TO_DIGESTS: ${OPERATOR_IMAGE_TAG}
- name: Archive the bundle
if: "startsWith(github.ref, 'refs/tags')"
run: tar czvf ${{ env.REPOSITORY_NAME }}-bundle-${{ env.BUNDLE_IMAGE_TAG }}.tar.gz bundle
- name: Upload bundle archive
uses: actions/upload-artifact@v2
with:
name: bundle-archive
path: ${{ env.REPOSITORY_NAME }}-bundle-${{ env.BUNDLE_IMAGE_TAG }}.tar.gz
release-github:
name: GitHub Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags')"
needs: ["build"]
permissions:
contents: write
packages: write
steps:
- name: set repo name
shell: bash
run: |
echo "REPOSITORY_NAME=$(basename $GITHUB_REPOSITORY)" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v2
- run: |
git fetch --prune --unshallow
- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Generate Changelog
run: |
LATEST_TAG=$(git tag --sort=creatordate | sed '$!d')
PREVIOUS_TAG=$(git tag --sort=creatordate | sed 'x;$!d')
if [ -z "${PREVIOUS_TAG}" ]; then
REV_RANGE=${LATEST_TAG}
else
REV_RANGE=${PREVIOUS_TAG}..${LATEST_TAG}
fi
git log --pretty=format:"- %s %H (%aN)" --no-merges ${REV_RANGE} > ${VERSION}-CHANGELOG.txt
cat ${VERSION}-CHANGELOG.txt
- name: Download bundle archive
uses: actions/download-artifact@v2
with:
name: bundle-archive
- name: Create Release
uses: softprops/action-gh-release@v1
with:
body_path: ${{ env.VERSION }}-CHANGELOG.txt
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload bundle to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.REPOSITORY_NAME }}-bundle-${{ env.VERSION }}.tar.gz
tag: ${{ github.ref }}
overwrite: true