|
| 1 | +name: Publish artifacts |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | + pull_request: |
| 12 | + branches: |
| 13 | + - main |
| 14 | + |
| 15 | +# note: we do not use any concurrency here, in order to avoid queued release workflows being cancelled by |
| 16 | +# higher priority push/pull_request workflows |
| 17 | + |
| 18 | +env: |
| 19 | + REGCTL_VERSION: v0.4.8 |
| 20 | + REGISTRY: ghcr.io |
| 21 | + |
| 22 | +defaults: |
| 23 | + run: |
| 24 | + shell: bash |
| 25 | + |
| 26 | +jobs: |
| 27 | + test: |
| 28 | + name: Run tests |
| 29 | + runs-on: ubuntu-22.04 |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout repository |
| 33 | + uses: actions/checkout@v3 |
| 34 | + |
| 35 | + - name: Setup go |
| 36 | + uses: actions/setup-go@v4 |
| 37 | + with: |
| 38 | + go-version-file: 'go.mod' |
| 39 | + |
| 40 | + - name: Check that license header boilerplate is correct |
| 41 | + run: | |
| 42 | + this_year=$(date +%Y) |
| 43 | + last_year=$((this_year-1)) |
| 44 | + repository=$(echo ${{ github.repository }} | cut -d/ -f2) |
| 45 | + boilerplate=hack/boilerplate.go.txt |
| 46 | +
|
| 47 | + tempdir=$(mktemp -d) |
| 48 | + trap 'rm -rf $tempdir' EXIT |
| 49 | +
|
| 50 | + cat > $tempdir/boilerplate-this-year <<END |
| 51 | + /* |
| 52 | + SPDX-FileCopyrightText: $this_year SAP SE or an SAP affiliate company and $repository contributors |
| 53 | + SPDX-License-Identifier: Apache-2.0 |
| 54 | + */ |
| 55 | + END |
| 56 | + cat > $tempdir/boilerplate-last-year <<END |
| 57 | + /* |
| 58 | + SPDX-FileCopyrightText: $last_year SAP SE or an SAP affiliate company and $repository contributors |
| 59 | + SPDX-License-Identifier: Apache-2.0 |
| 60 | + */ |
| 61 | + END |
| 62 | +
|
| 63 | + if diff -q $boilerplate $tempdir/boilerplate-this-year >/dev/null; then |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + if diff -q $boilerplate $tempdir/boilerplate-last-year >/dev/null; then |
| 67 | + >&1 echo "Warning: license boilerplate outdated ($last_year); next year, this will result in an error." |
| 68 | + exit 0 |
| 69 | + fi |
| 70 | + >&1 echo "Error: incorrect license boilerplate." |
| 71 | + exit 1 |
| 72 | + END |
| 73 | +
|
| 74 | + - name: Check that license headers are correct |
| 75 | + run: | |
| 76 | + boilerplate=hack/boilerplate.go.txt |
| 77 | +
|
| 78 | + tempdir=$(mktemp -d) |
| 79 | + trap 'rm -rf $tempdir' EXIT |
| 80 | +
|
| 81 | + boilerplate_linecount=$(wc -l $boilerplate | awk '{print $1}') |
| 82 | + errors=0 |
| 83 | +
|
| 84 | + for f in $(find . -name "*.go"); do |
| 85 | + if head -n 1 $f | grep -q "!ignore_autogenerated"; then |
| 86 | + continue |
| 87 | + fi |
| 88 | + head -n $boilerplate_linecount $f > $tempdir/out |
| 89 | + if ! diff -q $tempdir/out $boilerplate >/dev/null; then |
| 90 | + >&1 echo "Error: incorrect license header found in $f." |
| 91 | + errors=$((errors+1)) |
| 92 | + fi |
| 93 | + rm -f $tempdir/out |
| 94 | + done |
| 95 | +
|
| 96 | + if [ $errors -gt 0 ]; then |
| 97 | + exit 1 |
| 98 | + fi |
| 99 | +
|
| 100 | + - name: Check that generated artifacts are up-to-date |
| 101 | + run: | |
| 102 | + make generate |
| 103 | + echo "Running 'git status' ..." |
| 104 | + git status --porcelain | tee status.out |
| 105 | + if [[ -s status.out ]]; then |
| 106 | + >&1 echo "Generated artifacts are not up-to-date; probably 'make generate' was not run before committing." |
| 107 | + exit 1 |
| 108 | + else |
| 109 | + echo "Generated artifacts are up-to-date." |
| 110 | + fi |
| 111 | +
|
| 112 | + - name: Check that manifests are up-to-date |
| 113 | + run: | |
| 114 | + make manifests |
| 115 | + echo "Running 'git status' ..." |
| 116 | + git status --porcelain | tee status.out |
| 117 | + if [[ -s status.out ]]; then |
| 118 | + >&1 echo "Manifests are not up-to-date; probably 'make manifests' was not run before committing." |
| 119 | + exit 1 |
| 120 | + else |
| 121 | + echo "Manifests are up-to-date." |
| 122 | + fi |
| 123 | +
|
| 124 | + build-docker: |
| 125 | + name: Build Docker image |
| 126 | + runs-on: ubuntu-22.04 |
| 127 | + needs: test |
| 128 | + permissions: |
| 129 | + contents: read |
| 130 | + packages: write |
| 131 | + env: |
| 132 | + IMAGE_NAME: ${{ github.repository }} |
| 133 | + |
| 134 | + steps: |
| 135 | + - name: Checkout repository |
| 136 | + uses: actions/checkout@v3 |
| 137 | + |
| 138 | + - name: Set up Docker Buildx |
| 139 | + uses: docker/setup-buildx-action@v2 |
| 140 | + |
| 141 | + - name: Log in to the Container registry |
| 142 | + uses: docker/login-action@v2 |
| 143 | + with: |
| 144 | + registry: ${{ env.REGISTRY }} |
| 145 | + username: ${{ github.actor }} |
| 146 | + password: ${{ github.token }} |
| 147 | + |
| 148 | + - name: Prepare custom labels for Docker |
| 149 | + id: labels |
| 150 | + run: | |
| 151 | + echo "labels<<EOF" >> $GITHUB_OUTPUT |
| 152 | + for c in pkg/operator/data/charts/*/Chart.yaml; do |
| 153 | + name=$(yq .name $c) |
| 154 | + version=$(yq .version $c) |
| 155 | + app_version=$(yq .appVersion $c) |
| 156 | + echo "com.sap.cs.image.content.charts.$name.version=$version" >> $GITHUB_OUTPUT |
| 157 | + if [ ! -z "$app_version" ]; then |
| 158 | + echo "com.sap.cs.image.content.charts.$name.app-version=$app_version" >> $GITHUB_OUTPUT |
| 159 | + fi |
| 160 | + done |
| 161 | + echo "EOF" >> $GITHUB_OUTPUT |
| 162 | +
|
| 163 | + - name: Extract metadata (tags, labels) for Docker |
| 164 | + id: meta |
| 165 | + uses: docker/metadata-action@v4 |
| 166 | + with: |
| 167 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 168 | + labels: ${{ steps.labels.outputs.labels }} |
| 169 | + |
| 170 | + - name: Build Docker image |
| 171 | + uses: docker/build-push-action@v4 |
| 172 | + with: |
| 173 | + platforms: linux/amd64,linux/arm64 |
| 174 | + context: . |
| 175 | + cache-from: | |
| 176 | + type=gha,scope=sha-${{ github.sha }} |
| 177 | + type=gha,scope=${{ github.ref_name }} |
| 178 | + type=gha,scope=${{ github.base_ref || 'main' }} |
| 179 | + type=gha,scope=main |
| 180 | + cache-to: | |
| 181 | + type=gha,scope=sha-${{ github.sha }},mode=max |
| 182 | + type=gha,scope=${{ github.ref_name }},mode=max |
| 183 | + push: ${{ github.event_name == 'release' }} |
| 184 | + tags: ${{ steps.meta.outputs.tags }} |
| 185 | + labels: ${{ steps.meta.outputs.labels }} |
| 186 | + |
| 187 | + build-crds: |
| 188 | + name: Build CRD image |
| 189 | + runs-on: ubuntu-22.04 |
| 190 | + needs: test |
| 191 | + if: github.event_name == 'release' |
| 192 | + permissions: |
| 193 | + contents: read |
| 194 | + packages: write |
| 195 | + |
| 196 | + steps: |
| 197 | + - name: Checkout repository |
| 198 | + uses: actions/checkout@v3 |
| 199 | + |
| 200 | + - name: Setup regctl |
| 201 | + uses: regclient/actions/regctl-installer@main |
| 202 | + with: |
| 203 | + release: ${{ env.REGCTL_VERSION }} |
| 204 | + install-dir: ${{ runner.temp }}/bin |
| 205 | + |
| 206 | + - name: Log in to the registry |
| 207 | + # regctl-login action is currently broken ... |
| 208 | + # uses: regclient/actions/regctl-login@main |
| 209 | + # with: |
| 210 | + # registry: ${{ env.REGISTRY }} |
| 211 | + # username: ${{ github.actor }} |
| 212 | + # password: ${{ github.token }} |
| 213 | + run: | |
| 214 | + regctl registry login $REGISTRY --user ${{ github.actor }} --pass-stdin <<< ${{ github.token }} |
| 215 | +
|
| 216 | + - name: Build artifact |
| 217 | + run: | |
| 218 | + cd crds |
| 219 | + repository=${{ github.repository }}/crds |
| 220 | + tar cvz * | regctl artifact put -m application/gzip $REGISTRY/${repository,,}:${{ github.event.release.tag_name }} |
0 commit comments