Skip to content

Commit 8c852ad

Browse files
committed
Create Action workflow with custom patches applied and built
Docker build based on latest upstream release tags with our custom patches applied on top
1 parent bc7d599 commit 8c852ad

19 files changed

+2484
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Sync, Tag, Build and Publish Docker Image
2+
run-name: Patch and build ${{ github.event_name == 'schedule' && 'latest upstream tag' || inputs.tag }}
3+
4+
on:
5+
schedule:
6+
- cron: '0 0 * * *' # Daily at midnight
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: 'Specify a tag (optional)'
11+
required: false
12+
default: ''
13+
14+
jobs:
15+
sync-and-patch:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
pull-requests: write
20+
outputs:
21+
tag: ${{ steps.determine-tag.outputs.tag }}
22+
steps:
23+
# Step to checkout the 'ci' branch with patches
24+
- name: Checkout ci branch
25+
uses: actions/checkout@v3
26+
with:
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
ref: ci
29+
fetch-depth: 0
30+
31+
# Step to back up patches
32+
- name: Backup patches
33+
run: |
34+
mkdir -p $HOME/patches-backup
35+
cp patches/*.patch $HOME/patches-backup/
36+
37+
# Step to check out the repository's default branch
38+
- name: Checkout default branch
39+
uses: actions/checkout@v3
40+
with:
41+
token: ${{ secrets.PAT_TOKEN }}
42+
fetch-depth: 0
43+
44+
# Step to set up Git
45+
- name: Set up Git
46+
run: |
47+
git config --global user.name 'Bart van der Braak'
48+
git config --global user.email '[email protected]'
49+
50+
# Step to add upstream and fetch tags
51+
- name: Add upstream and fetch tags
52+
run: |
53+
git remote add upstream ${{ env.UPSTREAM }}
54+
# Prune tags from the fork to prevent conflicts
55+
git tag -l | xargs -n 1 git tag -d
56+
git fetch upstream --tags
57+
env:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
UPSTREAM: https://github.com/go-gitea/gitea.git
60+
61+
# Step to find the tag to use (input or latest)
62+
- name: Determine tag
63+
id: determine-tag
64+
run: |
65+
if [ -n "${{ github.event.inputs.tag }}" ]; then
66+
echo "Using manually specified tag: ${{ github.event.inputs.tag }}"
67+
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
68+
else
69+
echo "Finding the latest stable tag..."
70+
latest_tag=$(git tag -l "v*" --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
71+
echo "Latest stable tag: $latest_tag"
72+
echo "tag=$latest_tag" >> $GITHUB_OUTPUT
73+
fi
74+
75+
# Step to create a branch from the determined tag
76+
- name: Create branch from determined tag
77+
run: |
78+
git checkout -b apply-patches-${{ steps.determine-tag.outputs.tag }} ${{ steps.determine-tag.outputs.tag }}
79+
80+
# Step to apply patches and push partial progress if any apply
81+
- name: Apply patches and handle partial progress
82+
id: apply_patches
83+
run: |
84+
successful_patches=()
85+
failed_patches=()
86+
87+
for patch in $HOME/patches-backup/*.patch; do
88+
echo "Applying $patch..."
89+
if git am --3way "$patch"; then
90+
echo "Successfully applied $patch"
91+
successful_patches+=("$(basename "$patch")")
92+
else
93+
echo "Failed to apply patch: $patch"
94+
git am --abort
95+
failed_patches+=("$(basename "$patch")")
96+
break # Stop further patch application
97+
fi
98+
done
99+
100+
echo "successful_patches=${successful_patches[@]}" >> $GITHUB_ENV
101+
echo "failed_patches=${failed_patches[@]}" >> $GITHUB_ENV
102+
103+
# Push the branch even if only some patches were applied
104+
git push -f https://github.com/${{ github.repository }}.git HEAD
105+
env:
106+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
107+
108+
# Step to create a tag on the last commit of the patch branch
109+
- name: Create a tag on the last commit
110+
run: |
111+
git tag -d "${{ steps.determine-tag.outputs.tag }}" || echo "Tag does not exist locally, skipping delete."
112+
git tag -a "${{ steps.determine-tag.outputs.tag }}" -m "Tagging version ${{ steps.determine-tag.outputs.tag }} after applying patches"
113+
git push origin "${{ steps.determine-tag.outputs.tag }}"
114+
115+
build:
116+
runs-on: ubuntu-latest
117+
needs: sync-and-patch
118+
119+
permissions:
120+
contents: read # Read access to repository contents (required to access Dockerfile)
121+
packages: write # Write access to GHCR (required to publish Docker images)
122+
id-token: write # Needed for GHCR authentication
123+
124+
steps:
125+
# Set up Docker Buildx
126+
- name: Set up Docker Buildx
127+
uses: docker/setup-buildx-action@v2
128+
129+
# Log in to GitHub Container Registry
130+
- name: Log in to GitHub Container Registry
131+
uses: docker/login-action@v2
132+
with:
133+
registry: ghcr.io
134+
username: ${{ github.actor }}
135+
password: ${{ secrets.GITHUB_TOKEN }}
136+
137+
# Checkout the specific tag
138+
- name: Checkout tag
139+
uses: actions/checkout@v3
140+
with:
141+
ref: ${{ needs.sync-and-patch.outputs.tag }}
142+
143+
- name: Build and push Docker image
144+
uses: docker/build-push-action@v6
145+
with:
146+
push: true
147+
tags: ghcr.io/${{ github.repository }}:${{ needs.sync-and-patch.outputs.tag }}

0 commit comments

Comments
 (0)