Skip to content

Commit 320a5ea

Browse files
authored
Merge pull request #153 from cryptomator/feature/update-desktop-workflow
Feature: Workflow to update desktop downloads
2 parents d9ef3cb + a1ee165 commit 320a5ea

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Updates download urls to latest version
2+
3+
on:
4+
repository_dispatch:
5+
types: [desktop-release]
6+
7+
jobs:
8+
create-pr:
9+
name: Create PR for desktop release
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
env:
14+
DESKTOP_VERSION: ${{ github.event.client_payload.version }}
15+
steps:
16+
- name: Checkout repo
17+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
18+
- name: Create new branch
19+
run: |
20+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
21+
if [[ ! "$DESKTOP_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z]+)*$ ]]; then
22+
echo "Invalid version in payload: $DESKTOP_VERSION" >&2
23+
exit 1;
24+
fi
25+
git checkout -b "feature/desktop-${DESKTOP_VERSION}"
26+
- name: Update params.yaml
27+
run: |
28+
MSI_URL=$(jq -r '[.[] | select(.name | endswith(".msi"))][0].browser_download_url // "null"' <<< "$ASSETS_JSON")
29+
MSI_DIGEST=$(jq -r '[.[] | select(.name | endswith(".msi"))][0].digest // "null"' <<< "$ASSETS_JSON")
30+
EXE_URL=$(jq -r '[.[] | select(.name | endswith(".exe"))][0].browser_download_url // "null"' <<< "$ASSETS_JSON")
31+
EXE_DIGEST=$(jq -r '[.[] | select(.name | endswith(".exe"))][0].digest // "null"' <<< "$ASSETS_JSON")
32+
DMG_X64_URL=$(jq -r '[.[] | select(.name | endswith("-x64.dmg"))][0].browser_download_url // "null"' <<< "$ASSETS_JSON")
33+
DMG_X64_DIGEST=$(jq -r '[.[] | select(.name | endswith("-x64.dmg"))][0].digest // "null"' <<< "$ASSETS_JSON")
34+
DMG_ARM64_URL=$(jq -r '[.[] | select(.name | endswith("-arm64.dmg"))][0].browser_download_url // "null"' <<< "$ASSETS_JSON")
35+
DMG_ARM64_DIGEST=$(jq -r '[.[] | select(.name | endswith("-arm64.dmg"))][0].digest // "null"' <<< "$ASSETS_JSON")
36+
APPIMAGE_AARCH64_URL=$(jq -r '[.[] | select(.name | endswith("-aarch64.AppImage"))][0].browser_download_url // "null"' <<< "$ASSETS_JSON")
37+
APPIMAGE_AARCH64_DIGEST=$(jq -r '[.[] | select(.name | endswith("-aarch64.AppImage"))][0].digest // "null"' <<< "$ASSETS_JSON")
38+
APPIMAGE_X64_URL=$(jq -r '[.[] | select(.name | endswith("-x86_64.AppImage"))][0].browser_download_url // "null"' <<< "$ASSETS_JSON")
39+
APPIMAGE_X64_DIGEST=$(jq -r '[.[] | select(.name | endswith("-x86_64.AppImage"))][0].digest // "null"' <<< "$ASSETS_JSON")
40+
41+
UPDATED_ASSETS=0
42+
43+
update_release() {
44+
local key="$1"
45+
local url="$2"
46+
local digest="$3"
47+
local filename_expr="${4:-(env(RELEASE_URL) | split(\"/\") | .[-1])}"
48+
49+
if [ "$url" = "null" ] || [ -z "$url" ]; then
50+
return
51+
fi
52+
53+
if [[ "$url" != https://github.com/cryptomator/cryptomator/releases/download/* ]]; then
54+
echo "Unexpected download URL: $url" >&2
55+
exit 1
56+
fi
57+
58+
UPDATED_ASSETS=1
59+
RELEASE_URL="$url" RELEASE_DIGEST="${digest#sha256:}" yq -i "
60+
.releases.${key}.version = env(DESKTOP_VERSION) |
61+
.releases.${key}.filename = ${filename_expr} |
62+
.releases.${key}.downloadUrl = env(RELEASE_URL) |
63+
.releases.${key}.signatureUrl = (env(RELEASE_URL) + \".asc\") |
64+
.releases.${key}.checksum = env(RELEASE_DIGEST)
65+
" config/_default/params.yaml
66+
}
67+
68+
update_release "exe" "$EXE_URL" "$EXE_DIGEST"
69+
update_release "msi" "$MSI_URL" "$MSI_DIGEST"
70+
update_release "dmg" "$DMG_X64_URL" "$DMG_X64_DIGEST" '("Cryptomator-" + env(DESKTOP_VERSION) + ".dmg")'
71+
update_release '"dmg-arm64"' "$DMG_ARM64_URL" "$DMG_ARM64_DIGEST"
72+
update_release "appimage" "$APPIMAGE_X64_URL" "$APPIMAGE_X64_DIGEST"
73+
update_release '"appimage-aarch64"' "$APPIMAGE_AARCH64_URL" "$APPIMAGE_AARCH64_DIGEST"
74+
75+
if [ "$UPDATED_ASSETS" -eq 0 ]; then
76+
echo "No supported desktop assets found in release payload"
77+
exit 1
78+
fi
79+
env:
80+
ASSETS_JSON: ${{ toJson(github.event.client_payload.release.assets ) }}
81+
- name: Commit and push
82+
id: commit-and-push
83+
run: |
84+
git config user.name "cryptobot"
85+
git config user.email "cryptobot@users.noreply.github.com"
86+
git config push.autoSetupRemote true
87+
git stage config/_default/params.yaml
88+
if git diff --cached --quiet; then
89+
echo "No changes to commit"
90+
echo "changed=false" >> "$GITHUB_OUTPUT"
91+
exit 0
92+
fi
93+
git commit -m "Update desktop download urls to release ${DESKTOP_VERSION}"
94+
git push
95+
echo "changed=true" >> "$GITHUB_OUTPUT"
96+
- name: Create pull request
97+
id: create-pr
98+
if: steps.commit-and-push.outputs.changed == 'true'
99+
run: |
100+
printf "Created by $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > pr_body.md
101+
PR_URL=$(gh pr create --title "Desktop release ${DESKTOP_VERSION}" --body-file pr_body.md)
102+
echo "url=$PR_URL" >> "$GITHUB_OUTPUT"
103+
env:
104+
GH_TOKEN: ${{ secrets.CRYPTOBOT_PR_TOKEN }}
105+
- name: Slack Notification
106+
if: steps.commit-and-push.outputs.changed == 'true'
107+
uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661 # v2.3.3
108+
env:
109+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_CRYPTOMATOR_DESKTOP }}
110+
SLACK_USERNAME: 'Cryptobot'
111+
SLACK_ICON: ''
112+
SLACK_ICON_EMOJI: ':bot:'
113+
SLACK_CHANNEL: 'cryptomator-desktop'
114+
SLACK_TITLE: "Website update PR created for release ${{ github.event.client_payload.version }}."
115+
SLACK_MESSAGE: "See <${{ steps.create-pr.outputs.url }}|PR> on how to proceed."
116+
SLACK_FOOTER: ''
117+
MSG_MINIMAL: true

0 commit comments

Comments
 (0)