|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +env: |
| 9 | + REGISTRY: ghcr.io |
| 10 | + IMAGE_NAME: ${{ github.repository }} |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + packages: write |
| 18 | + id-token: write |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Set up Go |
| 27 | + uses: actions/setup-go@v4 |
| 28 | + with: |
| 29 | + go-version: '1.21' |
| 30 | + |
| 31 | + - name: Set up Helm |
| 32 | + uses: azure/setup-helm@v3 |
| 33 | + with: |
| 34 | + version: '3.12.0' |
| 35 | + |
| 36 | + - name: Set up Docker Buildx |
| 37 | + uses: docker/setup-buildx-action@v3 |
| 38 | + |
| 39 | + - name: Log in to Container Registry |
| 40 | + uses: docker/login-action@v3 |
| 41 | + with: |
| 42 | + registry: ${{ env.REGISTRY }} |
| 43 | + username: ${{ github.actor }} |
| 44 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Extract version from tag |
| 47 | + id: version |
| 48 | + run: | |
| 49 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 50 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 51 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 52 | +
|
| 53 | + - name: Update Chart.yaml with release version |
| 54 | + run: | |
| 55 | + sed -i "s/^version: .*/version: ${{ steps.version.outputs.version }}/" chart/Chart.yaml |
| 56 | + sed -i "s/^appVersion: .*/appVersion: \"${{ steps.version.outputs.version }}\"/" chart/Chart.yaml |
| 57 | +
|
| 58 | + - name: Run tests |
| 59 | + run: | |
| 60 | + go mod download |
| 61 | + make test |
| 62 | +
|
| 63 | + - name: Build and push Docker image |
| 64 | + uses: docker/build-push-action@v5 |
| 65 | + with: |
| 66 | + context: . |
| 67 | + platforms: linux/amd64,linux/arm64 |
| 68 | + push: true |
| 69 | + tags: | |
| 70 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} |
| 71 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest |
| 72 | + cache-from: type=gha |
| 73 | + cache-to: type=gha,mode=max |
| 74 | + |
| 75 | + - name: Package Helm chart |
| 76 | + run: | |
| 77 | + helm package chart --version ${{ steps.version.outputs.version }} --app-version ${{ steps.version.outputs.version }} |
| 78 | +
|
| 79 | + - name: Create GitHub Release |
| 80 | + uses: softprops/action-gh-release@v1 |
| 81 | + with: |
| 82 | + files: | |
| 83 | + flux-extension-controller-${{ steps.version.outputs.version }}.tgz |
| 84 | + generate_release_notes: true |
| 85 | + make_latest: true |
| 86 | + env: |
| 87 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 88 | + |
| 89 | + publish-helm-chart: |
| 90 | + runs-on: ubuntu-latest |
| 91 | + needs: release |
| 92 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 93 | + permissions: |
| 94 | + contents: read |
| 95 | + packages: write |
| 96 | + |
| 97 | + steps: |
| 98 | + - name: Checkout |
| 99 | + uses: actions/checkout@v4 |
| 100 | + |
| 101 | + - name: Set up Helm |
| 102 | + uses: azure/setup-helm@v3 |
| 103 | + with: |
| 104 | + version: '3.12.0' |
| 105 | + |
| 106 | + - name: Extract version from tag |
| 107 | + id: version |
| 108 | + run: | |
| 109 | + VERSION=${GITHUB_REF#refs/tags/v} |
| 110 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 111 | +
|
| 112 | + - name: Update Chart.yaml with release version |
| 113 | + run: | |
| 114 | + sed -i "s/^version: .*/version: ${{ steps.version.outputs.version }}/" chart/Chart.yaml |
| 115 | + sed -i "s/^appVersion: .*/appVersion: \"${{ steps.version.outputs.version }}\"/" chart/Chart.yaml |
| 116 | +
|
| 117 | + - name: Log in to Container Registry |
| 118 | + uses: docker/login-action@v3 |
| 119 | + with: |
| 120 | + registry: ${{ env.REGISTRY }} |
| 121 | + username: ${{ github.actor }} |
| 122 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 123 | + |
| 124 | + - name: Package and push Helm chart to OCI registry |
| 125 | + run: | |
| 126 | + helm package chart --version ${{ steps.version.outputs.version }} --app-version ${{ steps.version.outputs.version }} |
| 127 | + helm push flux-extension-controller-${{ steps.version.outputs.version }}.tgz oci://${{ env.REGISTRY }}/${{ github.repository }}/charts |
0 commit comments