update #200
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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/yq@v4.40.5 | |
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" |