|
| 1 | +name: Docker and Helm Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + issues: read |
| 9 | + pull-requests: read |
| 10 | + packages: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + release: |
| 14 | + name: Validate Docs, Tag, and Docker Push & Helm Push |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v3 |
| 18 | + with: |
| 19 | + token: ${{ secrets.BOT_TOKEN }} |
| 20 | + |
| 21 | + - name: Get New Chart Version |
| 22 | + id: nv |
| 23 | + run: | |
| 24 | + version=$(yq .version helm-charts/vmpooler/Chart.yaml) |
| 25 | + appVersion=$(yq .appVersion helm-charts/vmpooler/Chart.yaml) |
| 26 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 27 | + echo "appVersion=$appVersion" >> $GITHUB_OUTPUT |
| 28 | + echo "Found version $version from helm-charts/vmpooler/Chart.yaml" |
| 29 | + echo "Found appVersion $appVersion from helm-charts/vmpooler/Chart.yaml" |
| 30 | +
|
| 31 | + - name: Get Current Chart Version |
| 32 | + uses: actions/github-script@v6 |
| 33 | + id: cv |
| 34 | + with: |
| 35 | + script: | |
| 36 | + const { data: response } = await github.rest.repos.getLatestRelease({ |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + }) |
| 40 | + console.log(`The latest release is ${response.tag_name}`) |
| 41 | + return response.tag_name |
| 42 | + result-encoding: string |
| 43 | + |
| 44 | + - name: Get Current Docker Tag |
| 45 | + uses: actions/github-script@v6 |
| 46 | + id: dv |
| 47 | + with: |
| 48 | + script: | |
| 49 | + // concat to build "vmpooler-deployment%2Fvmpooler" |
| 50 | + const packageName = [context.repo.repo, 'vmpooler'].join('/'); |
| 51 | +
|
| 52 | + const shouldRunDockerBuild = async () => { |
| 53 | + let runDockerBuild = true; |
| 54 | + // Iterate through all pages of list of package versions |
| 55 | + for await (const response of github.paginate.iterator( |
| 56 | + github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg, |
| 57 | + { |
| 58 | + package_type: 'container', |
| 59 | + package_name: packageName, |
| 60 | + org: context.repo.owner, |
| 61 | + } |
| 62 | + )) { |
| 63 | + // Loop through each version, destructure down to the tags array and search for existing tag |
| 64 | + for (const data of response.data) { |
| 65 | + const { metadata: { container: { tags }}} = data; |
| 66 | + console.log('List of docker tags:', tags); |
| 67 | + if (tags.includes("${{ steps.nv.outputs.appVersion }}")) { |
| 68 | + // Existing tag found, return false so that docker build does not run |
| 69 | + console.log('Found existing tag for', "${{ steps.nv.outputs.appVersion }}"); |
| 70 | + runDockerBuild = false; |
| 71 | + break; |
| 72 | + }; |
| 73 | + }; |
| 74 | + }; |
| 75 | + return runDockerBuild; |
| 76 | + }; |
| 77 | +
|
| 78 | + const returnValue = await shouldRunDockerBuild(); |
| 79 | + console.log('return:', returnValue); |
| 80 | + return returnValue; |
| 81 | +
|
| 82 | + - name: Generate Changelog |
| 83 | + uses: docker://githubchangeloggenerator/github-changelog-generator:1.16.2 |
| 84 | + with: |
| 85 | + args: >- |
| 86 | + --future-release ${{ steps.nv.outputs.version }} |
| 87 | + env: |
| 88 | + CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + |
| 90 | + - name: Validate Changelog |
| 91 | + run : | |
| 92 | + set -e |
| 93 | + if [[ -n $(git status --porcelain) ]]; then |
| 94 | + echo "Here is the current git status:" |
| 95 | + git status |
| 96 | + echo |
| 97 | + echo "The following changes were detected:" |
| 98 | + git --no-pager diff |
| 99 | + echo "Uncommitted PRs found in the changelog. Please submit a release prep PR of changes after running 'docker run -it --rm -e CHANGELOG_GITHUB_TOKEN -v "\$\(pwd\)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator:1.16.2 github_changelog_generator --future-release ${{ steps.nv.outputs.version }}'" |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | +
|
| 103 | + - name: Generate Release Notes |
| 104 | + uses: docker://githubchangeloggenerator/github-changelog-generator:1.16.2 |
| 105 | + with: |
| 106 | + args: >- |
| 107 | + --since-tag ${{ steps.cv.outputs.result }} |
| 108 | + --future-release ${{ steps.nv.outputs.version }} |
| 109 | + --output release-notes.md |
| 110 | + env: |
| 111 | + CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + |
| 113 | + - name: Tag Release |
| 114 | + uses: ncipollo/release-action@v1 |
| 115 | + with: |
| 116 | + tag: ${{ steps.nv.outputs.version }} |
| 117 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + bodyfile: release-notes.md |
| 119 | + draft: false |
| 120 | + prerelease: false |
| 121 | + |
| 122 | + - name: Set up Docker Buildx |
| 123 | + uses: docker/setup-buildx-action@v2 |
| 124 | + |
| 125 | + - name: Login to GitHub Container Registry |
| 126 | + uses: docker/login-action@v2 |
| 127 | + with: |
| 128 | + registry: ghcr.io |
| 129 | + username: ${{ github.actor }} |
| 130 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + |
| 132 | + - name: Build and push Docker |
| 133 | + if: ${{ steps.dv.outputs.result == 'true' }} |
| 134 | + uses: docker/build-push-action@v3 |
| 135 | + with: |
| 136 | + push: true |
| 137 | + tags: | |
| 138 | + ghcr.io/${{ github.repository }}:${{ steps.nv.outputs.appVersion }} |
| 139 | + ghcr.io/${{ github.repository }}:latest |
| 140 | +
|
| 141 | + - uses: azure/setup-helm@v3 |
| 142 | + |
| 143 | + - uses: actions/setup-python@v4 |
| 144 | + with: |
| 145 | + python-version: 3.9 |
| 146 | + |
| 147 | + - name: Package Helm charts |
| 148 | + run: | |
| 149 | + set -e |
| 150 | + cd docs/ |
| 151 | + helm package ../helm-charts/* |
| 152 | + helm repo index --url https://puppetlabs.github.io/vmpooler-deployment/ . |
| 153 | +
|
| 154 | + - name: Git Commit and Push Helm Charts |
| 155 | + run: | |
| 156 | + git config user.name "puppetlabs-jenkins" |
| 157 | + git config user.email "[email protected]" |
| 158 | + git --no-pager diff CHANGELOG.md |
| 159 | + git add CHANGELOG.md |
| 160 | + git commit -m "release helm-chart version ${{ steps.nv.outputs.version }}" |
| 161 | + git push |
0 commit comments