|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + |
| 11 | +env: |
| 12 | + REGISTRY: ghcr.io |
| 13 | + IMAGE_NAME: ${{ github.repository }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + release: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: github.event_name != 'pull_request' |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + issues: write |
| 22 | + pull-requests: write |
| 23 | + packages: write |
| 24 | + |
| 25 | + outputs: |
| 26 | + new_release_published: ${{ steps.semantic.outputs.new_release_published }} |
| 27 | + new_release_version: ${{ steps.semantic.outputs.new_release_version }} |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - name: Setup Node.js |
| 36 | + uses: actions/setup-node@v4 |
| 37 | + with: |
| 38 | + node-version: 'lts/*' |
| 39 | + |
| 40 | + - name: Install semantic-release |
| 41 | + run: | |
| 42 | + npm install -g semantic-release @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/github |
| 43 | + |
| 44 | + - name: Create Release |
| 45 | + id: semantic |
| 46 | + env: |
| 47 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + run: npx semantic-release |
| 49 | + |
| 50 | + build-and-push: |
| 51 | + needs: release |
| 52 | + if: needs.release.outputs.new_release_published == 'true' |
| 53 | + runs-on: ubuntu-latest |
| 54 | + permissions: |
| 55 | + contents: read |
| 56 | + packages: write |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Checkout repository |
| 60 | + uses: actions/checkout@v4 |
| 61 | + |
| 62 | + - name: Set up Docker Buildx |
| 63 | + uses: docker/setup-buildx-action@v3 |
| 64 | + |
| 65 | + - name: Log in to GitHub Container Registry |
| 66 | + uses: docker/login-action@v3 |
| 67 | + with: |
| 68 | + registry: ${{ env.REGISTRY }} |
| 69 | + username: ${{ github.actor }} |
| 70 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + |
| 72 | + - name: Extract metadata for Docker |
| 73 | + id: meta |
| 74 | + uses: docker/metadata-action@v5 |
| 75 | + with: |
| 76 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 77 | + tags: | |
| 78 | + type=semver,pattern={{version}},value=v${{ needs.release.outputs.new_release_version }} |
| 79 | + type=semver,pattern={{major}}.{{minor}},value=v${{ needs.release.outputs.new_release_version }} |
| 80 | + type=raw,value=latest |
| 81 | +
|
| 82 | + - name: Build and push Docker image |
| 83 | + uses: docker/build-push-action@v5 |
| 84 | + with: |
| 85 | + context: . |
| 86 | + push: true |
| 87 | + tags: ${{ steps.meta.outputs.tags }} |
| 88 | + labels: ${{ steps.meta.outputs.labels }} |
| 89 | + cache-from: type=gha |
| 90 | + cache-to: type=gha,mode=max |
| 91 | + |
| 92 | + release-chart: |
| 93 | + needs: [release, build-and-push] |
| 94 | + if: needs.release.outputs.new_release_published == 'true' |
| 95 | + runs-on: ubuntu-latest |
| 96 | + permissions: |
| 97 | + contents: write |
| 98 | + pages: write |
| 99 | + |
| 100 | + steps: |
| 101 | + - name: Checkout |
| 102 | + uses: actions/checkout@v4 |
| 103 | + with: |
| 104 | + fetch-depth: 0 |
| 105 | + |
| 106 | + - name: Configure Git |
| 107 | + run: | |
| 108 | + git config user.name "$GITHUB_ACTOR" |
| 109 | + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" |
| 110 | +
|
| 111 | + - name: Install Helm |
| 112 | + uses: azure/setup-helm@v3 |
| 113 | + |
| 114 | + - name: Update chart version |
| 115 | + env: |
| 116 | + VERSION: ${{ needs.release.outputs.new_release_version }} |
| 117 | + run: | |
| 118 | + yq e -i '.version = env(VERSION)' charts/github-deploy-key-operator/Chart.yaml |
| 119 | + yq e -i '.appVersion = env(VERSION)' charts/github-deploy-key-operator/Chart.yaml |
| 120 | +
|
| 121 | + - name: Package Helm chart |
| 122 | + run: | |
| 123 | + helm package charts/github-deploy-key-operator |
| 124 | +
|
| 125 | + - name: Setup GitHub Pages |
| 126 | + uses: actions/configure-pages@v4 |
| 127 | + |
| 128 | + - name: Upload GitHub Pages artifact |
| 129 | + uses: actions/upload-pages-artifact@v3 |
| 130 | + with: |
| 131 | + path: '.' |
| 132 | + |
| 133 | + - name: Deploy GitHub Pages |
| 134 | + uses: actions/deploy-pages@v4 |
| 135 | + |
| 136 | + - name: Upload chart to release |
| 137 | + uses: softprops/action-gh-release@v1 |
| 138 | + with: |
| 139 | + tag_name: v${{ needs.release.outputs.new_release_version }} |
| 140 | + files: github-deploy-key-operator-*.tgz |
| 141 | + generate_release_notes: true |
0 commit comments