-
-
Notifications
You must be signed in to change notification settings - Fork 1
81 lines (65 loc) · 2.8 KB
/
update-flatpak-sources.yml
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
name: Update Flatpak Sources
on:
push:
branches:
- main
jobs:
update-flatpak-sources:
name: Get dependencies and update flatpak sources
runs-on: ubuntu-24.04
permissions:
contents: read # Only read access to repository contents
pull-requests: write # Write access for pull requests
steps:
# Step 1: Checkout the repository
- name: Checkout Code
uses: actions/checkout@v4
# Step 2: Set up JDK
- name: Set up JDK 23
uses: actions/setup-java@v3
with:
java-version: '23'
distribution: 'temurin'
# Step 3: Generate flatpak-sources.json
- name: Generate flatpak-sources.json
run: ./gradlew flatpakGradleGenerator
# Step 4: Compare flatpak-sources.json and create pull request if necessary
- name: Compare flatpak-sources.json and create pull request if necessary
run: |
git fetch origin main
BRANCH='update-flatpak-sources'
if ! diff -u <(jq . flatpak-sources.json) <(git show origin/main:flatpak-sources.json) >/dev/null; then
git config --global user.email "[email protected]"
git config --global user.name "ToxicStoxm"
# Fetch all branches from remote
git fetch origin
# Check if the branch exists remotely
if git ls-remote --heads origin $BRANCH | grep -q $BRANCH; then
echo "Branch $BRANCH exists on remote. Creating a local tracking branch."
# Temporarily stash changes
git stash --include-untracked
# Create a local branch that tracks the remote branch
git checkout -t origin/$BRANCH
# Restore stashed changes
git stash pop
else
echo "Branch $BRANCH does not exist. Creating a new branch."
git checkout -b $BRANCH
fi
# Check if there are any changes to commit
if git diff --quiet; then
echo "No changes to commit, skipping commit and PR creation."
else
# Stage and commit changes
git add flatpak-sources.json
git commit -m "Update flatpak-sources.json"
# Push the changes
git push --set-upstream origin $BRANCH
# Create a pull request
gh pr create -B main -H $BRANCH --title "Merge $BRANCH into main" --body "Created by Github action"
fi
else
echo "No changes detected in flatpak-sources.json. Skipping PR creation."
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}