|
| 1 | +--- |
| 2 | +name: build-ironic-hardware-exporter-images |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + version: |
| 8 | + description: 'Release version (X.Y.Z, without the v prefix)' |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + push: |
| 12 | + tags: |
| 13 | + - "ironic-hardware-exporter/v*" |
| 14 | + paths: |
| 15 | + - "go/ironic-hardware-exporter/**" |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-ironic-hardware-exporter: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + packages: write |
| 22 | + contents: write |
| 23 | + id-token: write |
| 24 | + outputs: |
| 25 | + version: ${{ steps.extract_tag.outputs.tag }} |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 29 | + with: |
| 30 | + fetch-depth: 0 |
| 31 | + |
| 32 | + - name: Install Go |
| 33 | + uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6 |
| 34 | + with: |
| 35 | + go-version: '1.25' |
| 36 | + cache: true |
| 37 | + cache-dependency-path: 'go/ironic-hardware-exporter/go.sum' |
| 38 | + |
| 39 | + - name: Install syft |
| 40 | + uses: anchore/sbom-action/download-syft@57aae528053a48a3f6235f2d9461b05fbcb7366d # v0.23.1 |
| 41 | + |
| 42 | + - name: Install Cosign |
| 43 | + uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0 |
| 44 | + |
| 45 | + - name: Set up QEMU |
| 46 | + uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4 |
| 47 | + |
| 48 | + - name: Set up Docker Buildx |
| 49 | + uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4 |
| 50 | + |
| 51 | + - name: Login to ghcr.io |
| 52 | + uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4 |
| 53 | + with: |
| 54 | + registry: "ghcr.io" |
| 55 | + username: ${{ github.actor }} |
| 56 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Validate tag format |
| 59 | + if: github.event_name != 'workflow_dispatch' |
| 60 | + run: | |
| 61 | + if [[ ! "$GITHUB_REF" =~ ^refs/tags/ironic-hardware-exporter/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then |
| 62 | + echo "Invalid tag: $GITHUB_REF — expected refs/tags/ironic-hardware-exporter/vX.Y.Z" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | +
|
| 66 | + - name: Validate version input |
| 67 | + if: github.event_name == 'workflow_dispatch' |
| 68 | + run: | |
| 69 | + if [[ ! "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 70 | + echo "Invalid version: ${{ inputs.version }} — expected X.Y.Z" |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | +
|
| 74 | + - name: Extract release version |
| 75 | + id: extract_tag |
| 76 | + run: | |
| 77 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 78 | + echo "tag=${{ inputs.version }}" >> $GITHUB_OUTPUT |
| 79 | + else |
| 80 | + echo "tag=${GITHUB_REF_NAME#ironic-hardware-exporter/v}" >> $GITHUB_OUTPUT |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Run GoReleaser |
| 84 | + uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6 |
| 85 | + with: |
| 86 | + distribution: goreleaser |
| 87 | + version: "~> v2" |
| 88 | + args: release --clean --skip=validate |
| 89 | + workdir: go/ironic-hardware-exporter |
| 90 | + env: |
| 91 | + GIT_REPO: ${{ github.repository }} |
| 92 | + RELEASE_VERSION: ${{ steps.extract_tag.outputs.tag }} |
| 93 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + |
| 95 | + chart: |
| 96 | + runs-on: ubuntu-latest |
| 97 | + needs: |
| 98 | + - build-ironic-hardware-exporter |
| 99 | + steps: |
| 100 | + - name: Checkout repository |
| 101 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 102 | + - name: Log in to ghcr.io |
| 103 | + uses: docker/login-action@b45d80f862d83dbcd57f89517bcf500b2ab88fb2 # v4 |
| 104 | + with: |
| 105 | + registry: ghcr.io |
| 106 | + username: '${{ github.actor }}' |
| 107 | + password: '${{ secrets.GITHUB_TOKEN }}' |
| 108 | + - name: Package and push Helm chart |
| 109 | + working-directory: go/ironic-hardware-exporter |
| 110 | + env: |
| 111 | + PKG_VER: '${{ needs.build-ironic-hardware-exporter.outputs.version }}' |
| 112 | + run: | |
| 113 | + yq -i ".version = \"${PKG_VER}\"" helm/Chart.yaml |
| 114 | + yq -i ".appVersion = \"${PKG_VER}\"" helm/Chart.yaml |
| 115 | + yq helm/Chart.yaml |
| 116 | + helm package -u -d ${{ github.workspace }} helm |
| 117 | + helm push ${{ github.workspace }}/ironic-hardware-exporter-${PKG_VER}.tgz \ |
| 118 | + oci://ghcr.io/${GITHUB_REPOSITORY_OWNER}/charts |
0 commit comments