Skip to content

Commit 36e7f44

Browse files
committed
Enable autoupdate (#582)
* add new error since DiffURL is not used (no patch bin) and optimize code * add first implementation of auto-update to release workflow * fix go-selfupdate not being found * use globally bash (for win compatibility) and move comment * uniform test.yml to release.yml
1 parent 936b6c8 commit 36e7f44

File tree

3 files changed

+58
-29
lines changed

3 files changed

+58
-29
lines changed

Diff for: .github/workflows/release.yml

+43-21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ on:
55
tags:
66
- "[0-9]+.[0-9]+.[0-9]+*"
77

8+
env:
9+
TARGET: "/CreateAgent/"
10+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
11+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
12+
AWS_REGION: "us-east-1" # or https://github.com/aws/aws-cli/issues/5623
13+
KEYCHAIN: "sign.keychain"
14+
INSTALLER_CERT_MAC_PATH: "/tmp/ArduinoCerts2020.p12"
15+
AC_USERNAME: ${{ secrets.AC_USERNAME }} # used by gon
16+
AC_PASSWORD: ${{ secrets.AC_PASSWORD }} # used by gon
17+
818
jobs:
919
# The build job is responsible for: configuring the environment, testing and compiling process
1020
build:
@@ -14,16 +24,31 @@ jobs:
1424
- operating-system: ubuntu-18.04
1525
- operating-system: windows-2019
1626
arch: -386
27+
ext: ".exe"
1728
- operating-system: windows-2019
1829
arch: -amd64
30+
ext: ".exe"
1931
- operating-system: macos-10.15
2032

33+
defaults:
34+
run:
35+
shell: bash
36+
2137
runs-on: ${{ matrix.operating-system }}
2238

2339
steps:
24-
- name: Set version
25-
run: echo "TAG_VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV
26-
shell: bash
40+
- name: Set env vars
41+
run: |
42+
echo "TAG_VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV
43+
echo $(go env GOPATH)/bin >> $GITHUB_PATH
44+
45+
- name: Identify Prerelease
46+
# This is a workaround while waiting for create-release action to implement auto pre-release based on tag
47+
id: prerelease
48+
run: |
49+
curl -L -s https://github.com/fsaintjacques/semver-tool/archive/3.1.0.zip -o /tmp/3.1.0.zip
50+
unzip -p /tmp/3.1.0.zip semver-tool-3.1.0/src/semver >/tmp/semver && chmod +x /tmp/semver
51+
if [[ $(/tmp/semver get prerel ${GITHUB_REF/refs\/tags\//}) ]]; then echo "::set-output name=IS_PRE::true"; fi
2752
2853
- name: Disable EOL conversions
2954
run: git config --global core.autocrlf false
@@ -48,7 +73,7 @@ jobs:
4873
run: |
4974
go get github.com/golangci/govet
5075
go get golang.org/x/lint/golint
51-
shell: bash
76+
go get -u github.com/sanbornm/go-selfupdate/...
5277
5378
- name: Install Taskfile
5479
uses: arduino/actions/setup-taskfile@master
@@ -97,6 +122,19 @@ jobs:
97122
run: task build
98123
if: matrix.operating-system == 'macos-10.15'
99124

125+
# this will create `public/` dir with compressed full bin (<version>/<os>-<arch>.gz) and a json file
126+
- name: Create autoupdate files
127+
run: go-selfupdate arduino-create-agent${{ matrix.ext }} ${TAG_VERSION}
128+
if: matrix.arch != '-386' && steps.prerelease.outputs.IS_PRE != 'true'
129+
130+
- name: Create autoupdate files for win32
131+
run: go-selfupdate -platform windows${{ matrix.arch }} arduino-create-agent${{ matrix.ext }} ${TAG_VERSION}
132+
if: matrix.arch == '-386' && steps.prerelease.outputs.IS_PRE != 'true'
133+
134+
- name: Upload autoupdate files to Arduino downloads servers
135+
run: aws s3 sync public/ s3://${{ secrets.DOWNLOADS_BUCKET }}${{ env.TARGET }}
136+
if: steps.prerelease.outputs.IS_PRE != 'true'
137+
100138
# config.ini is required by the executable when it's run
101139
- name: Upload artifacts
102140
uses: actions/upload-artifact@v2
@@ -122,9 +160,6 @@ jobs:
122160
path: arduino-create-agent-${{ env.RUNS_ON }}
123161

124162
- name: Import Code-Signing Certificates
125-
env:
126-
KEYCHAIN: "sign.keychain"
127-
INSTALLER_CERT_MAC_PATH: "/tmp/ArduinoCerts2020.p12"
128163
run: |
129164
echo "${{ secrets.INSTALLER_CERT_MAC_P12 }}" | base64 --decode > ${{ env.INSTALLER_CERT_MAC_PATH }}
130165
security create-keychain -p ${{ secrets.KEYCHAIN_PASSWORD }} ${{ env.KEYCHAIN }}
@@ -155,9 +190,6 @@ jobs:
155190
EOF
156191
157192
- name: Code sign and notarize app
158-
env:
159-
AC_USERNAME: ${{ secrets.AC_USERNAME }}
160-
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
161193
run: |
162194
echo "gon will notarize executable in arduino-create-agent-${{ env.RUNS_ON }}/arduino-create-agent"
163195
gon -log-level=debug -log-json gon.config.hcl
@@ -308,9 +340,6 @@ jobs:
308340
run: chmod -v +x ArduinoCreateAgent-osx/ArduinoCreateAgent-${GITHUB_REF##*/}-osx-installer-${{ matrix.browser }}.app/Contents/MacOS/*
309341

310342
- name: Import Code-Signing Certificates
311-
env:
312-
KEYCHAIN: "sign.keychain"
313-
INSTALLER_CERT_MAC_PATH: "/tmp/ArduinoCerts2020.p12"
314343
run: |
315344
echo "${{ secrets.INSTALLER_CERT_MAC_P12 }}" | base64 --decode > ${{ env.INSTALLER_CERT_MAC_PATH }}
316345
security create-keychain -p ${{ secrets.KEYCHAIN_PASSWORD }} ${{ env.KEYCHAIN }}
@@ -342,9 +371,6 @@ jobs:
342371
EOF
343372
344373
- name: Code sign and notarize app
345-
env:
346-
AC_USERNAME: ${{ secrets.AC_USERNAME }}
347-
AC_PASSWORD: ${{ secrets.AC_PASSWORD }}
348374
run: |
349375
echo "gon will notarize executable in ArduinoCreateAgent-osx/ArduinoCreateAgent-${GITHUB_REF##*/}-osx-installer-${{ matrix.browser }}.app"
350376
gon -log-level=debug -log-json gon.config_installer.hcl
@@ -364,10 +390,6 @@ jobs:
364390
create-release:
365391
runs-on: ubuntu-18.04
366392
needs: code-sign-mac-installers
367-
env:
368-
TARGET: "/CreateBridgeStable/"
369-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
370-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
371393

372394
steps:
373395
- name: Download artifact
@@ -377,7 +399,7 @@ jobs:
377399
# This is a workaround while waiting for create-release action to implement auto pre-release based on tag
378400
id: prerelease
379401
run: |
380-
wget -q -P /tmp https://github.com/fsaintjacques/semver-tool/archive/3.1.0.zip
402+
curl -L -s https://github.com/fsaintjacques/semver-tool/archive/3.1.0.zip -o /tmp/3.1.0.zip
381403
unzip -p /tmp/3.1.0.zip semver-tool-3.1.0/src/semver >/tmp/semver && chmod +x /tmp/semver
382404
if [[ $(/tmp/semver get prerel ${GITHUB_REF/refs\/tags\//}) ]]; then echo "::set-output name=IS_PRE::true"; fi
383405

Diff for: .github/workflows/test.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
- operating-system: windows-2019
1515
arch: -amd64
1616
- operating-system: macos-10.15
17+
defaults:
18+
run:
19+
shell: bash
1720

1821
runs-on: ${{ matrix.operating-system }}
1922

@@ -41,7 +44,6 @@ jobs:
4144
run: |
4245
go get github.com/golangci/govet
4346
go get golang.org/x/lint/golint
44-
shell: bash
4547
4648
- name: Install Taskfile
4749
uses: arduino/actions/setup-taskfile@master

Diff for: updater/updater.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ const (
5555
const devValidTime = 7 * 24 * time.Hour
5656

5757
var errHashMismatch = errors.New("new file hash mismatch after patch")
58+
var errDiffUrlUndefined = errors.New("DiffURL is not defined, I cannot fetch and apply patch, reverting to full bin")
5859
var up = update.New()
5960

60-
// TempPath generates a temporary path for the executable
61+
// TempPath generates a temporary path for the executable (adding "-temp")
6162
func TempPath(path string) string {
6263
if filepath.Ext(path) == "exe" {
6364
path = strings.Replace(path, ".exe", "-temp.exe", -1)
@@ -68,7 +69,7 @@ func TempPath(path string) string {
6869
return path
6970
}
7071

71-
// TempPath generates the proper path for a temporary executable
72+
// BinPath generates the proper path for a temporary executable (removing "-temp")
7273
func BinPath(path string) string {
7374
return strings.Replace(path, "-temp", "", -1)
7475
}
@@ -141,6 +142,9 @@ func verifySha(bin []byte, sha []byte) bool {
141142
}
142143

143144
func (u *Updater) fetchAndApplyPatch(old io.Reader) ([]byte, error) {
145+
if u.DiffURL == "" {
146+
return nil, errDiffUrlUndefined
147+
}
144148
r, err := fetch(u.DiffURL + u.CmdName + "/" + u.CurrentVersion + "/" + u.Info.Version + "/" + plat)
145149
if err != nil {
146150
return nil, err
@@ -238,12 +242,13 @@ func (u *Updater) update() error {
238242
}
239243
bin, err := u.fetchAndVerifyPatch(old)
240244
if err != nil {
241-
if err == errHashMismatch {
245+
switch err {
246+
case errHashMismatch:
242247
log.Println("update: hash mismatch from patched binary")
243-
} else {
244-
if u.DiffURL != "" {
245-
log.Println("update: patching binary,", err)
246-
}
248+
case errDiffUrlUndefined:
249+
log.Println("update: ", err)
250+
default:
251+
log.Println("update: patching binary, ", err)
247252
}
248253

249254
bin, err = u.fetchAndVerifyFullBin()

0 commit comments

Comments
 (0)