Skip to content

Commit 53fc1e0

Browse files
authored
feat: add homebrew cask release action (#56)
Adds homebrew cask auto-update workflow and improves VPN logging This change adds a new workflow to automatically update the homebrew cask when a new version of Coder Desktop is released. It also improves VPN logging by adding more debug logs and making the logger static, to avoid race conditions. Change-Id: I6e76a8fa519f378cda92b4edffa64c17294e01b9 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 270c7d0 commit 53fc1e0

File tree

4 files changed

+163
-5
lines changed

4 files changed

+163
-5
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ jobs:
7575
uses: ./.github/actions/nix-devshell
7676

7777
- run: make lint
78+
env:
79+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
name: release
22

33
on:
4+
push:
5+
branches:
6+
- main
47
release:
58
types: [published]
69

710
permissions: {}
811

912
jobs:
1013
build:
14+
name: Build Coder Desktop
1115
runs-on: ${{ github.repository_owner == 'coder' && 'depot-macos-latest' || 'macos-latest'}}
1216
if: ${{ github.repository_owner == 'coder' }}
1317
permissions:
@@ -40,7 +44,34 @@ jobs:
4044
run: make release
4145

4246
- name: Upload Release Assets
43-
run: gh release upload "$RELEASE_TAG" "$out"/*
47+
run: gh release upload "$RELEASE_TAG" "$out"/* --clobber
4448
env:
45-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46-
RELEASE_TAG: ${{ github.event.release.tag_name }}
49+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'preview' }}
51+
52+
update-cask:
53+
name: Update homebrew-coder cask
54+
runs-on: ${{ github.repository_owner == 'coder' && 'depot-macos-latest' || 'macos-latest'}}
55+
if: ${{ github.repository_owner == 'coder' }}
56+
needs: build
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
60+
with:
61+
fetch-depth: 1
62+
persist-credentials: false
63+
64+
- name: Setup Nix
65+
uses: ./.github/actions/nix-devshell
66+
67+
- name: Update homebrew-coder
68+
env:
69+
GH_TOKEN: ${{ secrets.CODERCI_GITHUB_TOKEN }}
70+
RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || 'preview' }}
71+
ASSIGNEE: ${{ github.actor }}
72+
run: |
73+
git config --global user.email "ci@coder.com"
74+
git config --global user.name "Coder CI"
75+
gh auth setup-git
76+
77+
./scripts/update-cask.sh --version "$RELEASE_TAG" --assignee "$ASSIGNEE"

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ XCPROJECT := Coder\ Desktop/Coder\ Desktop.xcodeproj
1111
SCHEME := Coder\ Desktop
1212
SWIFT_VERSION := 6.0
1313

14-
CURRENT_PROJECT_VERSION=$(shell git describe --tags)
14+
CURRENT_PROJECT_VERSION:=$(shell git describe --match 'v[0-9]*' --dirty='.devel' --always --tags)
1515
ifeq ($(strip $(CURRENT_PROJECT_VERSION)),)
1616
$(error CURRENT_PROJECT_VERSION cannot be empty)
1717
endif
1818

19-
MARKETING_VERSION=$(shell git describe --tags --abbrev=0 | sed 's/^v//' | sed 's/-.*$$//')
19+
MARKETING_VERSION:=$(shell git describe --match 'v[0-9]*' --tags --abbrev=0 | sed 's/^v//' | sed 's/-.*$$//')
2020
ifeq ($(strip $(MARKETING_VERSION)),)
2121
$(error MARKETING_VERSION cannot be empty)
2222
endif
@@ -132,3 +132,5 @@ help: ## Show this help
132132
.PHONY: watch-gen
133133
watch-gen: ## Generate Xcode project file and watch for changes
134134
watchexec -w 'Coder Desktop/project.yml' make $(XCPROJECT)
135+
136+
print-%: ; @echo $*=$($*)

scripts/update-cask.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
usage() {
5+
echo "Usage: $0 [--version <version>] [--assignee <github handle>]"
6+
echo " --version <version> Set the VERSION variable to fetch and generate the cask file for"
7+
echo " --assignee <github handle> Set the ASSIGNE variable to assign the PR to (optional)"
8+
echo " -h, --help Display this help message"
9+
}
10+
11+
VERSION=""
12+
ASSIGNE=""
13+
14+
# Parse command line arguments
15+
while [[ "$#" -gt 0 ]]; do
16+
case $1 in
17+
--version)
18+
VERSION="$2"
19+
shift 2
20+
;;
21+
--assignee)
22+
ASSIGNE="$2"
23+
shift 2
24+
;;
25+
-h | --help)
26+
usage
27+
exit 0
28+
;;
29+
*)
30+
echo "Unknown parameter passed: $1"
31+
usage
32+
exit 1
33+
;;
34+
esac
35+
done
36+
37+
# Assert version is not empty and starts with v
38+
[ -z "$VERSION" ] && {
39+
echo "Error: VERSION cannot be empty"
40+
exit 1
41+
}
42+
[[ "$VERSION" =~ ^v || "$VERSION" == "preview" ]] || {
43+
echo "Error: VERSION must start with a 'v'"
44+
exit 1
45+
}
46+
47+
# Download the Coder Desktop dmg
48+
GH_RELEASE_FOLDER=$(mktemp -d)
49+
50+
gh release download "$VERSION" \
51+
--repo coder/coder-desktop-macos \
52+
--dir "$GH_RELEASE_FOLDER" \
53+
--pattern 'Coder.Desktop.dmg'
54+
55+
HASH=$(shasum -a 256 "$GH_RELEASE_FOLDER"/Coder.Desktop.dmg | awk '{print $1}' | tr -d '\n')
56+
57+
IS_PREVIEW=false
58+
if [[ "$VERSION" == "preview" ]]; then
59+
IS_PREVIEW=true
60+
VERSION=$(make 'print-CURRENT_PROJECT_VERSION' | sed 's/CURRENT_PROJECT_VERSION=//g')
61+
fi
62+
63+
# Check out the homebrew tap repo
64+
TAP_CHECHOUT_FOLDER=$(mktemp -d)
65+
66+
gh repo clone "coder/homebrew-coder" "$TAP_CHECHOUT_FOLDER"
67+
68+
cd "$TAP_CHECHOUT_FOLDER"
69+
70+
BREW_BRANCH="auto-release/desktop-$VERSION"
71+
72+
# Check if a PR already exists.
73+
# Continue on a main branch release, as the sha256 will change.
74+
pr_count="$(gh pr list --search "head:$BREW_BRANCH" --json id,closed | jq -r ".[] | select(.closed == false) | .id" | wc -l)"
75+
if [[ "$pr_count" -gt 0 && "$IS_PREVIEW" == false ]]; then
76+
echo "Bailing out as PR already exists" 2>&1
77+
exit 0
78+
fi
79+
80+
git checkout -b "$BREW_BRANCH"
81+
82+
# If this is a main branch build, append a preview suffix to the cask.
83+
SUFFIX=""
84+
CONFLICTS_WITH="coder-desktop-preview"
85+
TAG=$VERSION
86+
if [[ "$IS_PREVIEW" == true ]]; then
87+
SUFFIX="-preview"
88+
CONFLICTS_WITH="coder-desktop"
89+
TAG="preview"
90+
fi
91+
92+
mkdir -p "$TAP_CHECHOUT_FOLDER"/Casks
93+
94+
# Overwrite the cask file
95+
cat >"$TAP_CHECHOUT_FOLDER"/Casks/coder-desktop${SUFFIX}.rb <<EOF
96+
cask "coder-desktop${SUFFIX}" do
97+
version "${VERSION#v}"
98+
sha256 "${HASH}"
99+
100+
url "https://github.com/coder/coder-desktop-macos/releases/download/${TAG}/Coder.Desktop.dmg"
101+
name "Coder Desktop"
102+
desc "Coder Desktop client"
103+
homepage "https://github.com/coder/coder-desktop-macos"
104+
105+
depends_on macos: ">= :sonoma"
106+
107+
app "Coder Desktop.app"
108+
conflicts_with cask: "coder/coder/${CONFLICTS_WITH}"
109+
end
110+
EOF
111+
112+
git add .
113+
git commit -m "Coder Desktop $VERSION"
114+
git push -u origin -f "$BREW_BRANCH"
115+
116+
# Create a PR only if none exists
117+
if [[ "$pr_count" -eq 0 ]]; then
118+
gh pr create \
119+
--base master --head "$BREW_BRANCH" \
120+
--title "Coder Desktop $VERSION" \
121+
--body "This automatic PR was triggered by the release of Coder Desktop $VERSION" \
122+
${ASSIGNE:+ --assignee "$ASSIGNE" --reviewer "$ASSIGNE"}
123+
fi

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy