refactoring done #14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'Build and draft release OCI Image' | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| branches-ignore: | |
| - 'master' | |
| jobs: | |
| validateCode: | |
| runs-on: 'ubuntu-24.04' | |
| permissions: | |
| contents: 'read' | |
| steps: | |
| - name: 'checkout code' | |
| uses: 'actions/checkout@v5' | |
| with: | |
| fetch-depth: 0 | |
| - name: 'populate env vars' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| GIT_COMMIT="$(git rev-parse HEAD)" | |
| GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})" | |
| BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" | |
| 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}'" | |
| GO_VERSION="$(go list -f {{.GoVersion}} -m)" | |
| echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV" | |
| echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV" | |
| echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV" | |
| echo "LDFLAGS=${LDFLAGS}" >> "$GITHUB_ENV" | |
| echo "GO_VERSION=${GO_VERSION}" >> "$GITHUB_ENV" | |
| - name: 'validate env vars' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| if [ "${GIT_TAG}" == "undefined" ]; then | |
| echo "no valid tag found" | |
| exit 1 | |
| fi | |
| - name: 'setup go' | |
| uses: 'actions/setup-go@v6' | |
| with: | |
| go-version: "${{ env.GO_VERSION }}" | |
| - name: 'golangci-lint' | |
| uses: 'golangci/golangci-lint-action@v8' | |
| with: | |
| version: 'v2.4.0' | |
| - name: 'govulncheck' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| go install golang.org/x/vuln/cmd/govulncheck@latest | |
| govulncheck -format text -show verbose ./... | |
| - name: 'go test' | |
| shell: 'bash' | |
| run: 'go test -ldflags "${LDFLAGS}" -cover ./...' | |
| - name: 'go build' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| go build -ldflags "${LDFLAGS}" -o check cmd/check/main.go | |
| go build -ldflags "${LDFLAGS}" -o in cmd/in/main.go | |
| go build -ldflags "${LDFLAGS}" -o out cmd/out/main.go | |
| - name: 'validate version' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| ./check -v | grep -q "${GIT_TAG}" | |
| ./in -v | grep -q "${GIT_TAG}" | |
| ./out -v | grep -q "${GIT_TAG}" | |
| buildImage: | |
| runs-on: 'ubuntu-24.04' | |
| needs: 'validateCode' | |
| permissions: | |
| contents: 'read' | |
| packages: 'write' | |
| steps: | |
| - name: 'checkout code' | |
| uses: 'actions/checkout@v5' | |
| with: | |
| fetch-depth: 0 | |
| - name: 'populate env vars' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| GIT_COMMIT="$(git rev-parse HEAD)" | |
| GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})" | |
| BUILD_DATE="$(date -u +'%Y-%m-%dT%H:%M:%SZ')" | |
| 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}'" | |
| GO_VERSION="$(go list -f {{.GoVersion}} -m)" | |
| echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV" | |
| echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV" | |
| echo "BUILD_DATE=${BUILD_DATE}" >> "$GITHUB_ENV" | |
| echo "LDFLAGS=${LDFLAGS}" >> "$GITHUB_ENV" | |
| echo "GO_VERSION=${GO_VERSION}" >> "$GITHUB_ENV" | |
| - name: 'validate env vars' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| if [ "${GIT_TAG}" == "undefined" ]; then | |
| echo "no valid tag found" | |
| exit 1 | |
| fi | |
| - name: 'setup go' | |
| uses: 'actions/setup-go@v6' | |
| with: | |
| go-version: "${{ env.GO_VERSION }}" | |
| - name: 'container registry login' | |
| uses: 'docker/login-action@v3' | |
| with: | |
| password: "${{ secrets.GITHUB_TOKEN }}" | |
| registry: 'ghcr.io' | |
| username: "${{ github.actor }}" | |
| - name: 'fetch metadata for the image build' | |
| id: 'meta' | |
| uses: 'docker/metadata-action@v5' | |
| with: | |
| images: "ghcr.io/${{ github.repository }}" | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=schedule,pattern={{date 'YYYYMMDD-hhmmss'}} | |
| type=raw,value=draft | |
| - name: 'build and push image' | |
| uses: 'docker/build-push-action@v6' | |
| with: | |
| context: '.' | |
| build-args: | | |
| BUILDER_VERSION=${{ env.GO_VERSION }}-bookworm | |
| GIT_COMMIT=${{ env.GIT_COMMIT }} | |
| GIT_TAG=${{ env.GIT_TAG }} | |
| BUILD_DATE=${{ env.BUILD_DATE}} | |
| labels: "${{ steps.meta.outputs.labels }}" | |
| tags: "${{ steps.meta.outputs.tags }}" | |
| platforms: 'linux/amd64' | |
| push: true | |
| createRelease: | |
| runs-on: 'ubuntu-24.04' | |
| needs: 'buildImage' | |
| permissions: | |
| contents: 'write' | |
| steps: | |
| - name: 'checkout code' | |
| uses: 'actions/checkout@v5' | |
| with: | |
| fetch-depth: 0 | |
| - name: 'populate env vars' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| GIT_COMMIT="$(git rev-parse HEAD)" | |
| GIT_TAG="$(git name-rev --tags --name-only ${GIT_COMMIT})" | |
| echo "GIT_COMMIT=${GIT_COMMIT}" >> "$GITHUB_ENV" | |
| echo "GIT_TAG=${GIT_TAG}" >> "$GITHUB_ENV" | |
| - name: 'validate env vars' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| if [ "${GIT_TAG}" == "undefined" ]; then | |
| echo "no valid tag found" | |
| exit 1 | |
| fi | |
| - name: 'install mdq' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| curl -LO https://github.com/yshavit/mdq/releases/download/v0.9.0/mdq-linux-x64.tar.gz | |
| tar -xf mdq-linux-x64.tar.gz | |
| rm mdq-linux-x64.tar.gz | |
| - name: 'maintain changelog' | |
| shell: 'bash' | |
| run: | | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| cat CHANGELOG.md | ./mdq "# ${GIT_TAG}" >changeLogForRelease.md | |
| echo '* `docker pull ghcr.io/sapcc/concourse-netbox-resource:${{ env.GIT_TAG }}`' >>changeLogForRelease.md | |
| cat changeLogForRelease.md | ./mdq "# ${GIT_TAG}" | |
| - name: 'create release' | |
| uses: 'ncipollo/release-action@v1' | |
| with: | |
| name: concourse-netbox-resource-${{ env.GIT_TAG }} | |
| bodyFile: 'changeLogForRelease.md' | |
| draft: true | |
| makeLatest: "legacy" | |
| tag: "${{ env.GIT_TAG }}" | |
| skipIfReleaseExists: true | |
| allowUpdates: true | |
| updateOnlyUnreleased: true |