|
| 1 | +name: Rebuild Bowtie Image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + pull_request: |
| 6 | + push: |
| 7 | + branches-ignore: |
| 8 | + - "wip*" |
| 9 | + |
| 10 | +env: |
| 11 | + IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: images-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +permissions: {} |
| 18 | + |
| 19 | +jobs: |
| 20 | + meta: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + outputs: |
| 23 | + latest-version: ${{ steps.version.outputs.value }} |
| 24 | + implementation-name: ${{ steps.impl.outputs.name }} |
| 25 | + steps: |
| 26 | + |
| 27 | + - name: Install bowtie |
| 28 | + uses: bowtie-json-schema/bowtie@main |
| 29 | + |
| 30 | + - name: Compute implementation name |
| 31 | + id: impl |
| 32 | + env: |
| 33 | + GH_REPOSITORY: ${{ github.repository }} |
| 34 | + run: echo "name=$(echo ${GH_REPOSITORY} | awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT |
| 35 | + |
| 36 | + - name: Compute latest implementation version |
| 37 | + id: version |
| 38 | + env: |
| 39 | + IMPL_NAME: ${{ steps.impl.outputs.name }} |
| 40 | + run: | |
| 41 | + version=$(bowtie info \ |
| 42 | + --implementation ${IMPL_NAME} \ |
| 43 | + --format json | jq -r '.version // empty') |
| 44 | + echo "value=${version}" >> $GITHUB_OUTPUT |
| 45 | +
|
| 46 | + build: |
| 47 | + needs: meta |
| 48 | + |
| 49 | + runs-on: ubuntu-latest |
| 50 | + |
| 51 | + outputs: |
| 52 | + current-version: ${{ steps.current-version.outputs.value }} |
| 53 | + |
| 54 | + permissions: |
| 55 | + id-token: write |
| 56 | + contents: read |
| 57 | + attestations: write |
| 58 | + packages: write |
| 59 | + |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@v4 |
| 62 | + with: |
| 63 | + persist-credentials: false |
| 64 | + |
| 65 | + - name: Install bowtie |
| 66 | + uses: bowtie-json-schema/bowtie@main |
| 67 | + |
| 68 | + - name: Build |
| 69 | + id: build_image |
| 70 | + uses: redhat-actions/buildah-build@v2 |
| 71 | + with: |
| 72 | + context: '.' |
| 73 | + containerfiles: | |
| 74 | + Dockerfile |
| 75 | + image: ${{ needs.meta.outputs.implementation-name }} |
| 76 | + tags: ${{ github.sha }} ${{ github.ref == 'refs/heads/main' && 'latest' || '' }} |
| 77 | + archs: amd64, arm64 |
| 78 | + |
| 79 | + - name: Set DOCKER_HOST so podman-built images are findable |
| 80 | + run: | |
| 81 | + systemctl --user enable --now podman.socket |
| 82 | + sudo loginctl enable-linger $USER |
| 83 | + podman --remote info |
| 84 | + echo "DOCKER_HOST=unix://$(podman info --format '{{.Host.RemoteSocket.Path}}')" >> $GITHUB_ENV |
| 85 | +
|
| 86 | + - name: Smoke Test |
| 87 | + env: |
| 88 | + IMAGE_WITH_TAG: ${{ steps.build_image.outputs.image-with-tag }} |
| 89 | + run: | |
| 90 | + bowtie smoke -i "localhost/${IMAGE_WITH_TAG}" --format json |
| 91 | + bowtie smoke -i "localhost/${IMAGE_WITH_TAG}" --format markdown >> $GITHUB_STEP_SUMMARY |
| 92 | +
|
| 93 | + - name: Collect current version |
| 94 | + id: current-version |
| 95 | + env: |
| 96 | + IMAGE_WITH_TAG: ${{ steps.build_image.outputs.image-with-tag }} |
| 97 | + run: | |
| 98 | + version=$(bowtie info \ |
| 99 | + --implementation "localhost/${IMAGE_WITH_TAG}" \ |
| 100 | + --format json | jq -r '.version // empty') |
| 101 | + echo "value=${version}" >> $GITHUB_OUTPUT |
| 102 | +
|
| 103 | + - name: Print collected versions |
| 104 | + env: |
| 105 | + LATEST_VERSION: ${{ needs.meta.outputs.latest-version }} |
| 106 | + CURRENT_VERSION: ${{ steps.current-version.outputs.value }} |
| 107 | + run: echo "latest_version=${LATEST_VERSION}; current_version=${CURRENT_VERSION}" |
| 108 | + |
| 109 | + - name: Log in to ghcr.io |
| 110 | + uses: redhat-actions/podman-login@v1 |
| 111 | + with: |
| 112 | + username: ${{ github.actor }} |
| 113 | + password: ${{ github.token }} |
| 114 | + registry: ${{ env.IMAGE_REGISTRY }} |
| 115 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 116 | + |
| 117 | + - name: Add tag with version to the image |
| 118 | + env: |
| 119 | + IMAGE_WITH_TAG: ${{ steps.build_image.outputs.image-with-tag }} |
| 120 | + IMAGE_WITH_VERSION: "${{ steps.build_image.outputs.image }}:${{ steps.current-version.outputs.value }}" |
| 121 | + run: podman tag ${IMAGE_WITH_TAG} ${IMAGE_WITH_VERSION} |
| 122 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 123 | + |
| 124 | + - name: Publish |
| 125 | + id: push |
| 126 | + uses: redhat-actions/push-to-registry@v2 |
| 127 | + with: |
| 128 | + image: ${{ steps.build_image.outputs.image }} |
| 129 | + tags: ${{ steps.current-version.outputs.value }} ${{ steps.build_image.outputs.tags }} |
| 130 | + registry: ${{ env.IMAGE_REGISTRY }} |
| 131 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 132 | + |
| 133 | + - name: Generate attestation for images |
| 134 | + uses: actions/attest-build-provenance@v2 |
| 135 | + with: |
| 136 | + subject-name: ${{ env.IMAGE_REGISTRY }}/${{ steps.build_image.outputs.image }} |
| 137 | + subject-digest: ${{ steps.push.outputs.digest }} |
| 138 | + push-to-registry: true |
| 139 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 140 | + |
| 141 | + mark-previous-version: |
| 142 | + needs: [build, meta] |
| 143 | + runs-on: ubuntu-latest |
| 144 | + |
| 145 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.build.outputs.current-version != needs.meta.outputs.latest-version |
| 146 | + |
| 147 | + permissions: |
| 148 | + contents: write |
| 149 | + |
| 150 | + env: |
| 151 | + TAG: v${{ needs.meta.outputs.latest-version }} |
| 152 | + COMMIT: ${{ github.event.before }} |
| 153 | + GH_REPOSITORY: ${{ github.repository }} |
| 154 | + |
| 155 | + steps: |
| 156 | + |
| 157 | + - name: Create a release for previous implementation version |
| 158 | + env: |
| 159 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 160 | + run: > |
| 161 | + gh api |
| 162 | + --method POST |
| 163 | + -H "Accept: application/vnd.github+json" |
| 164 | + -H "X-GitHub-Api-Version: 2022-11-28" |
| 165 | + /repos/${GH_REPOSITORY}/releases |
| 166 | + -f "tag_name=$TAG" |
| 167 | + -f "target_commitish=$COMMIT" |
| 168 | + -f "name=$TAG" |
| 169 | + -f "body=Automatic release for $TAG" |
| 170 | + -F "generate_release_notes=true" |
| 171 | +
|
| 172 | +
|
| 173 | + automerge: |
| 174 | + needs: build |
| 175 | + runs-on: ubuntu-latest |
| 176 | + |
| 177 | + if: (!cancelled() && github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]') |
| 178 | + |
| 179 | + permissions: |
| 180 | + contents: write |
| 181 | + pull-requests: write |
| 182 | + |
| 183 | + steps: |
| 184 | + - name: Automatically merge allowed PRs |
| 185 | + run: gh pr merge --auto --merge "$PR_URL" |
| 186 | + env: |
| 187 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 188 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments