Skip to content

Commit 31f30ff

Browse files
Add common and harness specific configuration for deployment and publication (#1)
* Add pre-commit config file * Add dependabot config * Add license * Add build workflow * Add automerge for dependabot PRs * Add missing bracket * Correct quotes * Remove dotnet condition * Remove --from when installing bowtie * Use correct package to install bowtie * Version is always set in the matrix * Try extract version from latest and current version and prepare a the tag when needed * Move part of tags to build image step * Print collected versions * Execute pre-commit hook * Use raw value in jq to get rid of quotes * Trigger image build only on a push to main branch * Correct which version is used for a tag * Add tag with version to the final image * Use gh cli to create tag and release * Add missing GH_TOKEN env variable * Use personal access token to create a tag and release * Use default github token for release creation * Use bowtie action * Add workflow to rebuild all available old version and the latest one (#2) This commit also adds `--platform=$BUILDPLATFORM` into Dockerfile to enable multi-arch builds without QEMU --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> * Add zizmor pre-commit hook and update workflow to comply with zizmor rules (#3) * Cleanup workflows * Use user.login to identify whether the PR is from dependabot * Remove manual tag creation. Use release API to create a tag --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 64d7715 commit 31f30ff

File tree

6 files changed

+379
-1
lines changed

6 files changed

+379
-1
lines changed

.github/dependabot.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2
2+
updates:
3+
# common configuration
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
- package-ecosystem: "docker"
9+
directory: "/"
10+
schedule:
11+
interval: "daily"
12+
13+
# test harnsess configuration
14+
- package-ecosystem: "gradle"
15+
directory: "/"
16+
schedule:
17+
interval: "daily"

.github/workflows/build-all.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
name: Build Bowtie Image for all available versions
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
8+
9+
permissions: {}
10+
11+
jobs:
12+
versions:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
revisions: ${{ steps.revisions.outputs.value }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
persist-credentials: false
20+
fetch-depth: 0
21+
fetch-tags: true
22+
- name: Collect available versions
23+
id: revisions
24+
run: |
25+
tags=$(jq -c -n '$ARGS.positional + ["main"]' --args $(git tag --list))
26+
echo "value=$(echo $tags | jq -c .)" >> $GITHUB_OUTPUT
27+
28+
build:
29+
needs: versions
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: true
33+
matrix:
34+
revision: ${{ fromJson(needs.versions.outputs.revisions) }}
35+
permissions:
36+
id-token: write
37+
contents: read
38+
attestations: write
39+
packages: write
40+
steps:
41+
- uses: actions/checkout@v4
42+
with:
43+
persist-credentials: false
44+
ref: ${{ matrix.revision }}
45+
46+
- name: Compute implementation name
47+
id: impl
48+
env:
49+
GH_REPOSITORY: ${{ github.repository }}
50+
run: echo "name=$(echo ${GH_REPOSITORY} | awk -F '/' '{print $2}')" >> $GITHUB_OUTPUT
51+
52+
- name: Install bowtie
53+
uses: bowtie-json-schema/bowtie@main
54+
55+
- name: Build
56+
id: build_image
57+
uses: redhat-actions/buildah-build@v2
58+
with:
59+
context: '.'
60+
containerfiles: |
61+
Dockerfile
62+
image: ${{ steps.impl.outputs.name }}
63+
tags: ${{ github.sha }} ${{ matrix.revision == 'main' && 'latest' || '' }}
64+
archs: amd64, arm64
65+
66+
- name: Set DOCKER_HOST so podman-built images are findable
67+
run: |
68+
systemctl --user enable --now podman.socket
69+
sudo loginctl enable-linger $USER
70+
podman --remote info
71+
echo "DOCKER_HOST=unix://$(podman info --format '{{.Host.RemoteSocket.Path}}')" >> $GITHUB_ENV
72+
73+
- name: Smoke Test
74+
env:
75+
IMAGE_WITH_TAG: ${{ steps.build_image.outputs.image-with-tag }}
76+
run: |
77+
bowtie smoke -i "localhost/${IMAGE_WITH_TAG}" --format json
78+
bowtie smoke -i "localhost/${IMAGE_WITH_TAG}" --format markdown >> $GITHUB_STEP_SUMMARY
79+
80+
- name: Collect current version
81+
id: current-version
82+
env:
83+
IMAGE_WITH_TAG: ${{ steps.build_image.outputs.image-with-tag }}
84+
run: |
85+
version=$(bowtie info \
86+
--implementation "localhost/${IMAGE_WITH_TAG}" \
87+
--format json | jq -r '.version // empty')
88+
echo "value=${version}" >> $GITHUB_OUTPUT
89+
90+
- name: Print collected version
91+
env:
92+
CURRENT_VERSION: ${{ steps.current-version.outputs.value }}
93+
run: echo "current_version=${CURRENT_VERSION}"
94+
95+
- name: Log in to ghcr.io
96+
uses: redhat-actions/podman-login@v1
97+
with:
98+
username: ${{ github.actor }}
99+
password: ${{ github.token }}
100+
registry: ${{ env.IMAGE_REGISTRY }}
101+
102+
- name: Add tag with version to the image
103+
env:
104+
IMAGE_WITH_TAG: ${{ steps.build_image.outputs.image-with-tag }}
105+
IMAGE_WITH_VERSION: "${{ steps.build_image.outputs.image }}:${{ steps.current-version.outputs.value }}"
106+
run: podman tag ${IMAGE_WITH_TAG} ${IMAGE_WITH_VERSION}
107+
108+
- name: Publish
109+
id: push
110+
uses: redhat-actions/push-to-registry@v2
111+
with:
112+
image: ${{ steps.build_image.outputs.image }}
113+
tags: ${{ steps.current-version.outputs.value }} ${{ steps.build_image.outputs.tags }}
114+
registry: ${{ env.IMAGE_REGISTRY }}
115+
116+
- name: Generate attestation for images
117+
uses: actions/attest-build-provenance@v2
118+
with:
119+
subject-name: ${{ env.IMAGE_REGISTRY }}/${{ steps.build_image.outputs.image }}
120+
subject-digest: ${{ steps.push.outputs.digest }}
121+
push-to-registry: true

.github/workflows/build.yml

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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 }}

.pre-commit-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
repos:
2+
# common hooks - should be added to template project
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v5.0.0
5+
hooks:
6+
- id: check-added-large-files
7+
- id: check-ast
8+
- id: check-json
9+
- id: check-toml
10+
- id: check-vcs-permalinks
11+
- id: check-yaml
12+
- id: debug-statements
13+
- id: end-of-file-fixer
14+
- id: mixed-line-ending
15+
args: [--fix, lf]
16+
- id: trailing-whitespace
17+
- repo: https://github.com/woodruffw/zizmor-pre-commit
18+
rev: v1.4.1
19+
hooks:
20+
- id: zizmor
21+
22+
# test harness specific hooks
23+
- repo: https://github.com/dustinsand/pre-commit-jvm
24+
rev: v0.11.0
25+
hooks:
26+
- name: ktlint (java/kotlin implementations)
27+
id: ktlint
28+
args: [--format]
29+
- name: detekt (java/kotlin implementations)
30+
id: detekt
31+
args: ["--build-upon-default-config"]

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM gradle:8.12.1-jdk17 AS builder
1+
FROM --platform=$BUILDPLATFORM gradle:8.12.1-jdk17 AS builder
22
WORKDIR /opt/app
33
COPY gradle/libs.versions.toml gradle/
44
COPY settings.gradle.kts .

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) 2022 Bowtie's Authors
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
20+
21+
Bowtie's logo was designed by @PaulWaller with work sponsored by [endjin](https://endjin.com).

0 commit comments

Comments
 (0)