🏭 Build Hcloud Metallb Controller #12
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 Hcloud Metallb Controller | |
| on: | |
| workflow_dispatch: | |
| push: | |
| tags: | |
| - "v[0-9]*.[0-9]*.[0-9]*" # Pattern for standard: v1.2.3 | |
| - "v[0-9]*.[0-9]*.[0-9]*-*" # Pattern for pre-release: v1.2.3-alpha.1 | |
| env: | |
| REGISTRY: ghcr.io | |
| PROJECT_PATH: "HcloudMetallbController/HcloudMetallbController.csproj" | |
| CHART_REPO: charts | |
| DOTNET_VERSION: "10.x" | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| pull-requests: read | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract repo names | |
| id: repoinfo | |
| shell: bash | |
| run: | | |
| REPOSITORY_LC=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') | |
| echo "repository_lc=$REPOSITORY_LC" >> $GITHUB_OUTPUT | |
| REPOSITORY_OWNER_LC=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') | |
| echo "repository_owner_lc=$REPOSITORY_OWNER_LC" >> $GITHUB_OUTPUT | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: ${{ env.DOTNET_VERSION }} | |
| - name: Install GitVersion | |
| uses: gittools/actions/gitversion/setup@v4.5.0 | |
| - name: Determine Version | |
| id: meta | |
| uses: gittools/actions/gitversion/execute@v4.5.0 | |
| - name: Log in to registry | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Publish container to registry | |
| env: | |
| REPOSITORY_LC: ${{ steps.repoinfo.outputs.repository_lc }} | |
| IMAGE_NAME: "hcloud-metallb-operator" | |
| ContainerImageTags: >- | |
| ${{ steps.meta.outputs.PreReleaseLabel != '' | |
| && format('{0};{1};{2}', steps.meta.outputs.SemVer, steps.meta.outputs.MajorMinorPath, steps.meta.outputs.InformationalVersion) | |
| || format('{0};{1}.{2};{3};latest', steps.meta.outputs.SemVer, steps.meta.outputs.Major, steps.meta.outputs.Minor, steps.meta.outputs.InformationalVersion) | |
| }} | |
| run: | | |
| dotnet publish \ | |
| ${{ env.PROJECT_PATH }} \ | |
| /t:PublishContainer \ | |
| -p ContainerRegistry=${{ env.REGISTRY }} \ | |
| -p ContainerRepository=${REPOSITORY_LC} | |
| - name: Get chart name | |
| id: chartname | |
| uses: mikefarah/yq@master | |
| with: | |
| cmd: yq -r .name deploy/Chart.yaml | |
| - name: Push Helm chart | |
| env: | |
| SEMVERSION: ${{ steps.meta.outputs.SemVer }} | |
| REPOSITORY_OWNER_LC: ${{ steps.repoinfo.outputs.repository_owner_lc }} | |
| CHART_NAME: ${{ steps.chartname.outputs.result }} | |
| run: | | |
| helm package ./deploy --version "$SEMVERSION" --app-version "$SEMVERSION" | |
| helm push ${CHART_NAME}-${SEMVERSION}.tgz oci://${{ env.REGISTRY }}/${REPOSITORY_OWNER_LC}/${{ env.CHART_REPO }} | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v3 | |
| # if: github.ref_type == 'tag' | |
| with: | |
| # tag_name: ${{ github.ref_name }} | |
| # name: "${{ github.ref_name }}" | |
| tag_name: ${{ github.ref_type == 'tag' && github.ref_name || format('v{0}', steps.meta.outputs.SemVer) }} | |
| name: ${{ github.ref_type == 'tag' && github.ref_name || format('v{0}', steps.meta.outputs.SemVer) }} | |
| generate_release_notes: true | |
| target_commitish: ${{ github.sha }} | |
| draft: false | |
| prerelease: ${{ steps.meta.outputs.PreReleaseTag != '' }} | |
| make_latest: ${{ steps.meta.outputs.PreReleaseTag == '' }} |