forked from researchxxl/syncthing-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-syncthing-submodule.yaml
More file actions
84 lines (76 loc) · 3.56 KB
/
Copy pathupdate-syncthing-submodule.yaml
File metadata and controls
84 lines (76 loc) · 3.56 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
83
84
name: Update Syncthing submodule
on:
schedule:
# Run every Wednesday at 19:00 UTC
- cron: '0 19 * * 3'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
update-syncthing-submodule:
name: Update Syncthing submodule
runs-on: ubuntu-latest
if: github.repository_owner == 'researchxxl'
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
submodules: true
fetch-depth: 0
- name: Get current submodule commit
id: current
run: |
CURRENT_COMMIT=$(git ls-tree HEAD syncthing/src/github.com/syncthing/syncthing | awk '{print $3}')
echo "commit=${CURRENT_COMMIT}" >> $GITHUB_OUTPUT
echo "Current commit: ${CURRENT_COMMIT}"
- name: Get latest syncthing release commit
id: latest
run: |
LATEST_TAG=$(curl -s https://api.github.com/repos/syncthing/syncthing/releases \
| jq -r 'map(select(.draft == false)) | .[0].tag_name')
echo "tag=${LATEST_TAG}" >> $GITHUB_OUTPUT
echo "Latest tag: ${LATEST_TAG}"
LATEST_COMMIT=$(git ls-remote https://github.com/syncthing/syncthing.git refs/tags/${LATEST_TAG}^{} | awk '{print $1}')
echo "commit=${LATEST_COMMIT}" >> $GITHUB_OUTPUT
echo "Latest commit: ${LATEST_COMMIT}"
- name: Update submodule if newer
if: ${{ steps.current.outputs.commit != steps.latest.outputs.commit }}
run: |
cd syncthing/src/github.com/syncthing/syncthing
git fetch origin "refs/tags/${{ steps.latest.outputs.tag }}"
git checkout "${{ steps.latest.outputs.tag }}"
cd -
git add syncthing/src/github.com/syncthing/syncthing
- name: Update versions.toml
if: ${{ steps.current.outputs.commit != steps.latest.outputs.commit }}
run: |
set -eu
TAG="${{ steps.latest.outputs.tag }}"
# Strip leading "v"
TAG="${TAG#v}"
# Extract major.minor.patch from tag (e.g. 2.0.12 from 2.0.12-rc.1)
BASE_VERSION=$(echo "$TAG" | sed -E 's/^([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
# Append .0 as required by your version scheme
NEW_VERSION="${BASE_VERSION}.0"
sed -i -E 's/version-name = "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"/version-name = "'"${NEW_VERSION}"'"/' gradle/libs.versions.toml
IFS='.' read -r MAJOR MINOR PATCH BUILD <<< "$NEW_VERSION"
VERSION_CODE=$(( MAJOR*1000000 + MINOR*10000 + PATCH*100 + BUILD ))
sed -i -E 's/version-code = "[0-9]+"/version-code = "'"${VERSION_CODE}"'"/' gradle/libs.versions.toml
git add gradle/libs.versions.toml
echo "Updated version to: ${NEW_VERSION} (${VERSION_CODE})"
- name: Create Pull Request if commit changed
if: ${{ steps.current.outputs.commit != steps.latest.outputs.commit }}
uses: peter-evans/create-pull-request@98357b18bf14b5342f975ff684046ec3b2a07725 # v8.0.0
with:
branch: "bump-syncthing-${{ steps.latest.outputs.tag }}"
commit-message: "Bump Syncthing submodule to ${{ steps.latest.outputs.tag }}"
title: "Bump Syncthing submodule to ${{ steps.latest.outputs.tag }}"
body: |
Bump Syncthing submodule to ${{ steps.latest.outputs.tag }}
labels: dependencies
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
base: main
add-paths: |
gradle/libs.versions.toml
syncthing/src/github.com/syncthing/syncthing
delete-branch: true