-
Notifications
You must be signed in to change notification settings - Fork 8
69 lines (60 loc) · 2.51 KB
/
update.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
# This workflow checks if a new Zotero release is available. If so, it
# updates the snapcraft.yaml file and commits the changes to the repository.
# It runs every day at midnight UTC, and can also be triggered manually.
name: update
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Detect Zotero Linux Version
id: zotero
run: |
# Use curl to follow the redirect and capture the final URL
url=$(curl -Ls -o /dev/null -w %{url_effective} 'https://www.zotero.org/download/client/dl?channel=release&platform=linux-x86_64')
# Extract the version from the URL
version=$(echo "$url" | grep -oP 'Zotero-\K[0-9.]+(?=_linux-x86_64.tar.bz2)')
echo "Latest Zotero version for Linux: $version"
echo "version=$version" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get Zotero-Snap version
id: snap
uses: mikefarah/[email protected]
with:
cmd: yq '.version' snap/snapcraft.yaml
- name: Compare versions
run: |
zotero=${{ steps.zotero.outputs.version }}
snap=${{ steps.snap.outputs.result }}
if [ "$zotero" == "$snap" ]; then
echo Zotero-Snap is up to date
else
echo "New Zotero release available: $snap => $zotero"
echo "new_version=$zotero" >> "$GITHUB_ENV"
fi
- name: Update snapcraft.yaml
if: ${{ env.new_version }}
run: |
echo "Updating snapcraft.yaml to ${{ env.new_version }}"
# Use sed instead of yq, because yq deletes empty lines
sed -i "s/^version: .*/version: '${{ env.new_version }}'/" snap/snapcraft.yaml
- name: Commit changes
if: ${{ env.new_version }}
uses: stefanzweifel/git-auto-commit-action@v5
id: auto-commit-action
with:
commit_message: Update Zotero-Snap to ${{ env.new_version }}
create_branch: true
branch: ${{ env.new_version }}
- name: Create PR
if: steps.auto-commit-action.outputs.changes_detected == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
sleep 3 # wait for github to get the created pr
gh pr create -H "${{ env.new_version }}" -B master --title "update zotero to ${{ env.new_version }}" --body "Created by Github action"