|
| 1 | +name: 'Build and draft release OCI Image' |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - 'v*' |
| 6 | + branches-ignore: |
| 7 | + - '**' |
| 8 | +jobs: |
| 9 | + validateCode: |
| 10 | + runs-on: 'ubuntu-24.04' |
| 11 | + permissions: |
| 12 | + contents: 'read' |
| 13 | + steps: |
| 14 | + - name: 'checkout code' |
| 15 | + uses: 'actions/checkout@v5' |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + - name: 'populate env vars' |
| 19 | + shell: 'bash' |
| 20 | + run: | |
| 21 | + #!/usr/bin/env bash |
| 22 | + set -euo pipefail |
| 23 | +
|
| 24 | + GIT_COMMIT="$(git rev-parse HEAD)" |
| 25 | + GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})" |
| 26 | + BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" |
| 27 | + LDFLAGS="-X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitCommit=${GIT_COMMIT}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.buildDate=${BUILD_DATE}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitVersion=${GIT_TAG}'" |
| 28 | + GO_VERSION="$(go list -f {{.GoVersion}} -m)" |
| 29 | + echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV" |
| 30 | + echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV" |
| 31 | + echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV" |
| 32 | + echo "LDFLAGS=${LDFLAGS}" >> "$GITHUB_ENV" |
| 33 | + echo "GO_VERSION=${GO_VERSION}" >> "$GITHUB_ENV" |
| 34 | + - name: 'validate env vars' |
| 35 | + shell: 'bash' |
| 36 | + run: | |
| 37 | + #!/usr/bin/env bash |
| 38 | + set -euo pipefail |
| 39 | +
|
| 40 | + if [ "${GIT_TAG}" == "undefined" ]; then |
| 41 | + echo "no valid git tag found" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + - name: 'setup go' |
| 45 | + uses: 'actions/setup-go@v6' |
| 46 | + with: |
| 47 | + go-version: "${{ env.GO_VERSION }}" |
| 48 | + - name: 'golangci-lint' |
| 49 | + uses: 'golangci/golangci-lint-action@v8' |
| 50 | + with: |
| 51 | + version: 'v2.4.0' |
| 52 | + - name: 'govulncheck' |
| 53 | + shell: 'bash' |
| 54 | + run: | |
| 55 | + #!/usr/bin/env bash |
| 56 | + set -euo pipefail |
| 57 | +
|
| 58 | + go install golang.org/x/vuln/cmd/govulncheck@latest |
| 59 | + govulncheck -format text -show verbose ./... |
| 60 | + - name: 'go test' |
| 61 | + shell: 'bash' |
| 62 | + run: 'go test -ldflags "${LDFLAGS}" -cover ./...' |
| 63 | + - name: 'go build' |
| 64 | + shell: 'bash' |
| 65 | + run: | |
| 66 | + #!/usr/bin/env bash |
| 67 | + set -euo pipefail |
| 68 | +
|
| 69 | + go build -ldflags "${LDFLAGS}" -o check cmd/check/main.go |
| 70 | + go build -ldflags "${LDFLAGS}" -o in cmd/in/main.go |
| 71 | + go build -ldflags "${LDFLAGS}" -o out cmd/out/main.go |
| 72 | + - name: 'validate version' |
| 73 | + shell: 'bash' |
| 74 | + run: | |
| 75 | + #!/usr/bin/env bash |
| 76 | + set -euo pipefail |
| 77 | +
|
| 78 | + ./check -v | grep -q "${GIT_TAG}" |
| 79 | + ./in -v | grep -q "${GIT_TAG}" |
| 80 | + ./out -v | grep -q "${GIT_TAG}" |
| 81 | + buildImage: |
| 82 | + runs-on: 'ubuntu-24.04' |
| 83 | + needs: 'validateCode' |
| 84 | + permissions: |
| 85 | + contents: 'read' |
| 86 | + packages: 'write' |
| 87 | + steps: |
| 88 | + - name: 'checkout code' |
| 89 | + uses: 'actions/checkout@v5' |
| 90 | + with: |
| 91 | + fetch-depth: 0 |
| 92 | + - name: 'populate env vars' |
| 93 | + shell: 'bash' |
| 94 | + run: | |
| 95 | + #!/usr/bin/env bash |
| 96 | + set -euo pipefail |
| 97 | +
|
| 98 | + GIT_COMMIT="$(git rev-parse HEAD)" |
| 99 | + GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})" |
| 100 | + BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" |
| 101 | + LDFLAGS="-X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitCommit=${GIT_COMMIT}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.buildDate=${BUILD_DATE}' -X 'github.com/sapcc/concourse-netbox-resource/pkg/helper.gitVersion=${GIT_TAG}'" |
| 102 | + GO_VERSION="$(go list -f {{.GoVersion}} -m)" |
| 103 | + echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV" |
| 104 | + echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV" |
| 105 | + echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV" |
| 106 | + echo "LDFLAGS=${LDFLAGS}" >> "$GITHUB_ENV" |
| 107 | + echo "GO_VERSION=${GO_VERSION}" >> "$GITHUB_ENV" |
| 108 | + - name: 'validate env vars' |
| 109 | + shell: 'bash' |
| 110 | + run: | |
| 111 | + #!/usr/bin/env bash |
| 112 | + set -euo pipefail |
| 113 | +
|
| 114 | + if [ "${GIT_TAG}" == "undefined" ]; then |
| 115 | + echo "no valid git tag found" |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | + - name: 'setup go' |
| 119 | + uses: 'actions/setup-go@v6' |
| 120 | + with: |
| 121 | + go-version: "${{ env.GO_VERSION }}" |
| 122 | + - name: 'container registry login' |
| 123 | + uses: 'docker/login-action@v3' |
| 124 | + with: |
| 125 | + password: "${{ secrets.GITHUB_TOKEN }}" |
| 126 | + registry: 'ghcr.io' |
| 127 | + username: "${{ github.actor }}" |
| 128 | + - name: 'fetch metadata for the image build' |
| 129 | + id: 'meta' |
| 130 | + uses: 'docker/metadata-action@v5' |
| 131 | + with: |
| 132 | + images: "ghcr.io/${{ github.repository }}" |
| 133 | + tags: | |
| 134 | + type=ref,event=branch |
| 135 | + type=semver,pattern={{version}} |
| 136 | + type=semver,pattern={{major}}.{{minor}} |
| 137 | + type=schedule,pattern={{date 'YYYYMMDD-hhmmss'}} |
| 138 | + type=raw,value=draft |
| 139 | + - name: 'build and push image' |
| 140 | + uses: 'docker/build-push-action@v6' |
| 141 | + with: |
| 142 | + context: '.' |
| 143 | + build-args: | |
| 144 | + BUILDER_VERSION=${{ env.GO_VERSION }}-bookworm |
| 145 | + GIT_COMMIT=${{ env.GIT_COMMIT }} |
| 146 | + GIT_TAG=${{ env.GIT_TAG }} |
| 147 | + BUILD_DATE=${{ env.BUILD_DATE}} |
| 148 | + labels: "${{ steps.meta.outputs.labels }}" |
| 149 | + tags: "${{ steps.meta.outputs.tags }}" |
| 150 | + platforms: 'linux/amd64' |
| 151 | + push: true |
| 152 | + createRelease: |
| 153 | + runs-on: 'ubuntu-24.04' |
| 154 | + needs: 'buildImage' |
| 155 | + permissions: |
| 156 | + contents: 'write' |
| 157 | + steps: |
| 158 | + - name: 'checkout code' |
| 159 | + uses: 'actions/checkout@v5' |
| 160 | + with: |
| 161 | + fetch-depth: 0 |
| 162 | + - name: 'populate env vars' |
| 163 | + shell: 'bash' |
| 164 | + run: | |
| 165 | + #!/usr/bin/env bash |
| 166 | + set -euo pipefail |
| 167 | +
|
| 168 | + GIT_COMMIT="$(git rev-parse HEAD)" |
| 169 | + GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})" |
| 170 | + echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV" |
| 171 | + echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV" |
| 172 | + - name: 'validate env vars' |
| 173 | + shell: 'bash' |
| 174 | + run: | |
| 175 | + #!/usr/bin/env bash |
| 176 | + set -euo pipefail |
| 177 | +
|
| 178 | + if [ "${GIT_TAG}" == "undefined" ]; then |
| 179 | + echo "no valid git tag found" |
| 180 | + exit 1 |
| 181 | + fi |
| 182 | + - name: 'install mdq' |
| 183 | + shell: 'bash' |
| 184 | + run: | |
| 185 | + #!/usr/bin/env bash |
| 186 | + set -euo pipefail |
| 187 | +
|
| 188 | + curl -LO https://github.com/yshavit/mdq/releases/download/v0.9.0/mdq-linux-x64.tar.gz |
| 189 | + tar -xf mdq-linux-x64.tar.gz |
| 190 | + rm mdq-linux-x64.tar.gz |
| 191 | + - name: 'maintain changelog' |
| 192 | + shell: 'bash' |
| 193 | + run: | |
| 194 | + #!/usr/bin/env bash |
| 195 | + set -euo pipefail |
| 196 | +
|
| 197 | + cat CHANGELOG.md | ./mdq "# ${GIT_TAG}" >changeLogForRelease.md |
| 198 | + echo '* `docker pull ghcr.io/sapcc/concourse-netbox-resource:${{ env.GIT_TAG }}`' >>changeLogForRelease.md |
| 199 | + cat changeLogForRelease.md | ./mdq "# ${GIT_TAG}" |
| 200 | + - name: 'create release' |
| 201 | + uses: 'ncipollo/release-action@v1' |
| 202 | + with: |
| 203 | + name: concourse-netbox-resource-${{ env.GIT_TAG }} |
| 204 | + bodyFile: 'changeLogForRelease.md' |
| 205 | + draft: true |
| 206 | + makeLatest: "legacy" |
| 207 | + tag: "${{ env.GIT_TAG }}" |
| 208 | + skipIfReleaseExists: true |
| 209 | + allowUpdates: true |
| 210 | + updateOnlyUnreleased: true |
0 commit comments