Skip to content

Commit beef3e0

Browse files
committed
playing with github actions
1 parent da6a28c commit beef3e0

4 files changed

Lines changed: 214 additions & 1 deletion

File tree

.github/workflows/docker-build.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Version & Docker
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
types: [closed]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
13+
determine-version:
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: write
18+
19+
outputs:
20+
SemVer: ${{ steps.gitversion.outputs.SemVer }}
21+
22+
steps:
23+
- name: Checkout repo
24+
uses: actions/checkout@v5
25+
with:
26+
fetch-depth: 0
27+
28+
# Prüfen des Labels für Version Bump
29+
- name: Determine Version Bump
30+
id: version-bump
31+
uses: actions/github-script@v7
32+
with:
33+
github-token: ${{ secrets.GITHUB_TOKEN }}
34+
script: |
35+
const allowedLabels = ["major version","minor version","patch version"];
36+
const labels = context.payload.pull_request.labels.map(l => l.name);
37+
const matching = labels.filter(l => allowedLabels.includes(l));
38+
if (matching.length !== 1) {
39+
core.setFailed(
40+
`PR must have exactly one version label: ${allowedLabels.join(", ")}. Found: ${matching.join(", ") || "none"}`
41+
);
42+
} else {
43+
core.setOutput("bump", matching[0].replace(" version",""));
44+
}
45+
46+
# GitVersion für main Merge
47+
- name: Run GitVersion
48+
id: gitversion
49+
uses: gittools/actions/gitversion/execute@v3
50+
with:
51+
versionSpec: "5.x"
52+
updateAssemblyInfo: false
53+
showVariable: SemVer
54+
increment: ${{ steps.version-bump.outputs.bump }}
55+
56+
- name: Show calculated version
57+
run: echo "Calculated Version: ${{ steps.gitversion.outputs.SemVer }}"
58+
59+
- name: Tag Version
60+
run: |
61+
git config --global user.email "github_actions@company.com"
62+
git config --global user.name "GitHub Actions"
63+
git tag -a "v${{ steps.gitversion.outputs.SemVer }}" -m "Release ${{ steps.gitversion.outputs.SemVer }}"
64+
git push origin "v${{ steps.gitversion.outputs.SemVer }}"
65+
66+
docker-build-main:
67+
runs-on: ubuntu-latest
68+
needs: determine-version
69+
70+
steps:
71+
- name: Checkout repo
72+
uses: actions/checkout@v5
73+
74+
- name: Set up Docker Buildx
75+
uses: docker/setup-buildx-action@v3
76+
77+
- name: Docker metadata
78+
id: metadata
79+
uses: docker/metadata-action@v5
80+
with:
81+
images: myorg/middleware
82+
tags: v${{ needs.determine-version.outputs.SemVer }}
83+
84+
- name: Build & Push Docker Image
85+
uses: docker/build-push-action@v6
86+
with:
87+
push: true
88+
tags: ${{ steps.metadata.outputs.tags }}
89+
build-args: python_version=3.12
90+
91+
create-release:
92+
runs-on: ubuntu-latest
93+
needs: docker-build-main
94+
permissions:
95+
contents: write
96+
97+
steps:
98+
- name: Create GitHub Release
99+
uses: ncipollo/release-action@v1
100+
with:
101+
tag: v${{ needs.determine-version.outputs.SemVer }}
102+
name: "Release v${{ needs.determine-version.outputs.SemVer }}"
103+
body: |
104+
Docker image: `myorg/middleware:v${{ needs.determine-version.outputs.SemVer }}`
105+
draft: false
106+
prerelease: false
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Feature Build
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: write # damit wir den VERSION-Commit pushen können
8+
9+
jobs:
10+
feature-build:
11+
runs-on: ubuntu-latest
12+
13+
env:
14+
GIT_USER_NAME: GitHub Pipeline
15+
GIT_USER_EMAIL: github_pipeline@fairagro.net
16+
IMAGE_NAME: zalf/fairagro_advanced_middleware_api
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v5
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up GitVersion
25+
id: gitversion
26+
uses: gittools/actions/gitversion/execute@v3
27+
with:
28+
versionSpec: 5.x
29+
updateAssemblyInfo: false
30+
showVariable: FullSemVer
31+
32+
- name: Show computed feature version
33+
run: 'echo "Feature Version: ${{ steps.gitversion.outputs.FullSemVer }}"'
34+
35+
- name: Update pyproject.toml with feature version and create tag
36+
run: |
37+
VERSION="${{ steps.gitversion.outputs.FullSemVer }}"
38+
echo "Updating pyproject.toml version to $VERSION"
39+
40+
# Backup
41+
cp pyproject.toml pyproject.toml.bak
42+
43+
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml
44+
45+
# Optional commit
46+
git config user.name "${{ env.GIT_USER_NAME }}"
47+
git config user.email "{{ env.GIT_USER_EMAIL }}"
48+
git add pyproject.toml
49+
git commit -m "Update version to $VERSION" || echo "No changes to commit"
50+
git tag -a "v${VERSION}" -m "Release $VERSION"
51+
git push origin HEAD:${GITHUB_REF#refs/heads/}
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v3
57+
58+
- name: Docker metadata
59+
id: metadata
60+
uses: docker/metadata-action@v5
61+
with:
62+
images: ${{ env.IMAGE_NAME }}
63+
tags: ${{ steps.gitversion.outputs.FullSemVer }}
64+
65+
# TODO: implement container structure tests
66+
# - name: Build and export to Docker
67+
# uses: docker/build-push-action@v6
68+
# with:
69+
# load: true
70+
# tags: middleware:test
71+
# labels: ${{ steps.metadata.outputs.labels }} # we need the labels as they're checked for
72+
73+
# - name: Test image
74+
# uses: plexsystems/container-structure-test-action@v0.3.0
75+
# with:
76+
# image: middleware:test
77+
# config: test/container-structure-test/container-structure-test-config.yml
78+
79+
# Secrets are managed within the github GUI
80+
- name: Log in to Docker Hub
81+
uses: docker/login-action@v3
82+
with:
83+
username: ${{ secrets.DOCKERHUB_USER }}
84+
password: ${{ secrets.DOCKERHUB_TOKEN }}
85+
86+
- name: Build & Push Docker Image
87+
uses: docker/build-push-action@v6
88+
with:
89+
push: true
90+
tags: ${{ steps.metadata.outputs.tags }}
91+
labels: ${{ steps.metadata.outputs.labels }}
92+

.trunk/trunk.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ plugins:
1313
runtimes:
1414
enabled:
1515
- node@22.16.0
16-
- python@3.10.8
16+
- python@3.12.10
1717
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
1818
lint:
1919
enabled:

GitVersion.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
mode: Mainline
2+
tag-prefix: v
3+
4+
branches:
5+
main:
6+
increment: Patch
7+
prevent-increment-of-merged-branch-version: true
8+
9+
feature:
10+
increment: Patch
11+
source-branches: [main]
12+
tag: useBranchName
13+
prevent-increment-of-merged-branch-version: true
14+
regex: ^feature/(?<BranchName>.+)$
15+
is-source-branch-for: []

0 commit comments

Comments
 (0)