-
Notifications
You must be signed in to change notification settings - Fork 42
83 lines (72 loc) · 2.3 KB
/
Copy pathsync-and-build.yml
File metadata and controls
83 lines (72 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Sync upstream and build image
on:
schedule:
- cron: "23 4 * * 1" # Mondays 04:23 UTC
workflow_dispatch: {}
permissions:
contents: write # to push to main
packages: write # to push to GHCR
env:
UPSTREAM_REPO: JustTemmie/steam-presence
BRANCH: main
IMAGE_NAME: steam-presence
jobs:
sync:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.check.outputs.changed }}
steps:
- name: Checkout fork
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Add upstream and fetch
run: |
git remote add upstream https://github.com/${{ env.UPSTREAM_REPO }}.git || true
git fetch upstream ${{ env.BRANCH }}
- name: Check behind/ahead and merge if needed
id: check
run: |
git checkout $BRANCH
read BEHIND AHEAD < <(git rev-list --left-right --count upstream/$BRANCH...$BRANCH | awk '{print $1" "$2}')
echo "Behind: $BEHIND Ahead: $AHEAD"
if [ "$BEHIND" -gt 0 ]; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git merge --no-edit upstream/$BRANCH
git push origin $BRANCH
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "No changes to sync."
echo "changed=false" >> $GITHUB_OUTPUT
fi
build:
needs: sync
if: needs.sync.outputs.changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout updated main
uses: actions/checkout@v4
with:
ref: main
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=ref,event=branch
type=sha
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}