Skip to content

Commit 3bc427f

Browse files
committed
devops: Update release process for Github
1 parent 87bf16d commit 3bc427f

15 files changed

+239
-123
lines changed

.github/workflows/main.yml

+65-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
name: Test/Release
1+
name: Test-Release
22
on: [push]
33

44
jobs:
5-
test_maybe_release:
6-
name: Test (then release if new version)
5+
tests:
6+
name: "Tests (webextension, interfacer: unit, tty, http-server)"
77
runs-on: ubuntu-latest
88
env:
99
GOPATH: ${{ github.workspace }}
1010
GOBIN: ${{ github.workspace }}/bin
11+
outputs:
12+
is_new_version: ${{ steps.check_versions.outputs.is_new_version }}
1113
steps:
1214
- name: Checkout
1315
uses: actions/checkout@v3
@@ -16,15 +18,15 @@ jobs:
1618
- name: Setup go
1719
uses: actions/setup-go@v3
1820
with:
19-
go-version: 1.18.x
21+
go-version-file: 'interfacer/go.mod'
2022
- name: Setup node
2123
uses: actions/setup-node@v3
2224
with:
23-
node-version: 16
25+
node-version-file: '.nvmrc'
2426
- name: Install Firefox
2527
uses: browser-actions/setup-firefox@latest
2628
with:
27-
firefox-version: 102.0.1 # TODO: Use same version in Dockerfile
29+
firefox-version: 102.0.1
2830
- run: firefox --version
2931

3032
# Web extension tests
@@ -33,14 +35,13 @@ jobs:
3335
- name: Web extension tests
3436
run: npm test
3537
working-directory: ./webext
36-
- run: npm run build_webextension
37-
working-directory: ./webext
3838

3939
# Interfacer tests
40-
- name: Build
41-
run: go build ./cmd/browsh
42-
working-directory: ./interfacer
43-
40+
- name: Interfacer tests setup
41+
run: |
42+
touch interfacer/src/browsh/browsh.xpi
43+
cd webext
44+
npm run build:dev
4445
- name: Unit tests
4546
run: go test -v $(find src/browsh -name '*.go' | grep -v windows)
4647
working-directory: ./interfacer
@@ -51,25 +52,72 @@ jobs:
5152
if: ${{ failure() }}
5253
run: cat ./interfacer/test/tty/debug.log || echo "No log file"
5354
- name: HTTP Server tests
54-
run: go test test/http-server/*.go -v -ginkgo.slowSpecThreshold=30 -ginkgo.flakeAttempts=3
55-
working-directory: ./interfacer
55+
uses: nick-fields/retry@v2
56+
with:
57+
max_attempts: 3
58+
retry_on: error
59+
timeout_minutes: 15
60+
command: |
61+
cd interfacer
62+
go test test/http-server/*.go -v -ginkgo.slowSpecThreshold=30 -ginkgo.flakeAttempts=3
5663
- name: HTTP Server debug log
5764
if: ${{ failure() }}
5865
run: cat ./interfacer/test/http-server/debug.log || echo "No log file"
5966

60-
# Release
6167
- name: Check for new version
6268
id: check_versions
6369
run: ./ctl.sh github_actions_output_version_status
64-
- name: Release
65-
if: contains(steps.check_versions.outputs.is_new_version, 'true')
70+
71+
release:
72+
name: Release
73+
runs-on: ubuntu-latest
74+
needs: tests
75+
if: github.ref == 'refs/heads/master' && contains(needs.tests.outputs.is_new_version, 'true')
76+
env:
77+
GOPATH: ${{ github.workspace }}
78+
GOBIN: ${{ github.workspace }}/bin
79+
MDN_KEY: ${{ secrets.MDN_KEY }}
80+
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
steps:
83+
- name: Setup Deploy Keys
84+
uses: webfactory/[email protected]
85+
with:
86+
# Note that these private keys depend on having an ssh-keygen'd comment with the
87+
# Git remote URL. This is because Github Actions use the *first* matching private
88+
# key and fails if it doesn't match. webfactory/ssh-agent
89+
ssh-private-key: |
90+
${{ secrets.HOMEBREW_DEPLOY_KEY }}
91+
${{ secrets.WWW_DEPLOY_KEY }}
92+
- name: Checkout
93+
uses: actions/checkout@v3
94+
with:
95+
fetch-depth: 0
96+
- name: Setup node
97+
uses: actions/setup-node@v3
98+
with:
99+
node-version-file: '.nvmrc'
100+
- name: Setup go
101+
uses: actions/setup-go@v3
102+
with:
103+
go-version-file: 'interfacer/go.mod'
104+
- run: npm ci
105+
working-directory: ./webext
106+
- name: Binary Release
66107
run: ./ctl.sh release
108+
- name: Push new tag
109+
uses: ad-m/github-push-action@master
110+
with:
111+
github_token: ${{ secrets.GITHUB_TOKEN }}
112+
tags: true
67113
- name: Login to Docker Hub
68114
uses: docker/login-action@v2
69115
with:
70116
username: tombh
71117
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
72118
- name: Docker Release
73119
run: ./ctl.sh docker_release
120+
- name: Update Homebrew Tap
121+
run: ./ctl.sh update_homebrew_tap_with_new_version
74122
- name: Update Browsh Website
75123
run: ./ctl.sh update_browsh_website_with_new_version

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,14 @@ webext/node_modules
1212
webext/dist/*
1313
dist
1414
*.xpi
15+
16+
# This is because of an odd permissions quirk on Github Actions. I can't seem to find a
17+
# way to delete these files in CI, so let's just ignore them. Otherwise Goreleaser complains
18+
# about a dirty working tree.
19+
/pkg
20+
/bin
21+
22+
# Goreleaser needs to upload the webextension as an extra file in the release. But it doesn't
23+
# like Git to be in a dirty state. Also Goreleaser is run at PWD ./interfacer, so we can't
24+
# reference the webextension with something like ../webext/...
25+
interfacer/browsh-*.xpi

Dockerfile

+6-8
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,19 @@ ADD .github .github
2424
ADD scripts scripts
2525
ADD ctl.sh .
2626

27-
# Install Golang
27+
# Install Golang and Browsh
2828
ENV GOROOT=/go
2929
ENV GOPATH=/go-home
3030
ENV PATH=$GOROOT/bin:$GOPATH/bin:$PATH
31-
RUN /build/ctl.sh install_golang
32-
33-
# Install firefox
34-
RUN /build/ctl.sh install_firefox
35-
36-
# Build Browsh
3731
ENV BASE=$GOPATH/src/browsh/interfacer
38-
WORKDIR $BASE
3932
ADD interfacer $BASE
33+
WORKDIR $BASE
34+
RUN /build/ctl.sh install_golang $BASE
4035
RUN /build/ctl.sh build_browsh_binary $BASE
4136

37+
# Install firefox
38+
RUN /build/ctl.sh install_firefox
39+
4240

4341
###########################
4442
# Actual final Docker image

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ is running somewhere else on mains electricity.
3535

3636
## Installation
3737

38-
Download a binary from the [releases](https://github.com/browsh-org/browsh/releases) (~7MB).
39-
You will need to have [Firefox 63](https://www.mozilla.org/en-US/firefox/new/) (or higher) already installed.
38+
Download a binary from the [releases](https://github.com/browsh-org/browsh/releases) (~11MB).
39+
You will need to have [Firefox](https://www.mozilla.org/en-US/firefox/new/) already installed.
4040

4141
Or download and run the Docker image (~230MB) with:
4242
`docker run --rm -it browsh/browsh`

ctl.sh

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#!/bin/env bash
1+
#!/usr/bin/env bash
22
set -e
33

44
function_to_run=$1
55

6-
export PROJECT_ROOT && PROJECT_ROOT=$(git rev-parse --show-toplevel)
6+
export PROJECT_ROOT
77
export GORELEASER_VERSION=1.10.2
8-
export GOBINDATA_VERSION=3.23.0
8+
9+
PROJECT_ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
910

1011
function _includes_path {
1112
echo "$PROJECT_ROOT"/scripts
@@ -26,4 +27,7 @@ if [[ $(type -t "$function_to_run") != function ]]; then
2627
fi
2728

2829
shift
30+
31+
pushd "$PROJECT_ROOT" || _panic
2932
"$function_to_run" "$@"
33+
popd || _panic

goreleaser.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,14 @@ nfpms:
5757
brews:
5858
- name: browsh
5959
tap:
60-
owner: browsh-org
6160
name: homebrew-browsh
62-
commit_author:
63-
name: Goreleaser Bot care of Github Actions
64-
6561
homepage: "https://www.brow.sh"
6662
description: "The modern, text-based browser"
6763
caveats: "You need Firefox 57 or newer to run Browsh"
64+
# We do the upload manually because Goreleaser doesn't support Deploy Keys and Github
65+
# doesn't support repo-specific Access Tokens 🙄
66+
skip_upload: true
6867

6968
release:
7069
extra_files:
71-
- glob: ./webext/dist/web-ext-artifacts/browsh-{{ Env.BROWSH_VERSION }}-an+fx.xpi
70+
- glob: ./browsh-*.xpi

interfacer/contrib/setup_firefox.sh

-26
This file was deleted.

interfacer/src/browsh/firefox.go

-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,6 @@ func firefoxMarionette() {
230230
sendFirefoxCommand("WebDriver:NewSession", map[string]interface{}{})
231231
}
232232

233-
// Install the Browsh extension that was bundled with `go-bindata` under
234-
// `webextension.go`.
235233
func installWebextension() {
236234
data, err := browshXpi.ReadFile("browsh.xpi")
237235
if err != nil {

interfacer/src/browsh/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package browsh
22

3-
var browshVersion = "1.6.4"
3+
var browshVersion = "1.8.0"

scripts/bundling.bash

+65-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
#!/usr/bin/env bash
22

3-
function build_webextension() {
4-
local NODE_BIN=$PROJECT_ROOT/webext/node_modules/.bin
3+
export XPI_PATH="$PROJECT_ROOT"/interfacer/src/browsh/browsh.xpi
4+
export XPI_SOURCE_DIR=$PROJECT_ROOT/webext/dist/web-ext-artifacts
5+
export NODE_BIN=$PROJECT_ROOT/webext/node_modules/.bin
6+
MDN_USER="user:13243312:78"
7+
8+
function versioned_xpi_file() {
9+
echo "$XPI_SOURCE_DIR/browsh-$(browsh_version).xpi"
10+
}
11+
12+
# You'll want to use this with `go run ./cmd/browsh --debug --firefox.use-existing`
13+
function build_webextension_watch() {
14+
"$NODE_BIN"/web-ext run \
15+
--firefox contrib/firefoxheadless.sh \
16+
--verbose
17+
}
18+
19+
function build_webextension_production() {
20+
local version && version=$(browsh_version)
521

622
cd "$PROJECT_ROOT"/webext && "$NODE_BIN"/webpack
723
cd "$PROJECT_ROOT"/webext/dist && rm ./*.map
@@ -13,36 +29,63 @@ function build_webextension() {
1329
"$NODE_BIN"/web-ext build --overwrite-dest
1430
ls -alh web-ext-artifacts
1531

16-
version=$(browsh_version)
32+
webextension_sign
33+
local source_file && source_file=$(versioned_xpi_file)
34+
35+
echo "Bundling $source_file to $XPI_PATH"
36+
cp -f "$source_file" "$XPI_PATH"
1737

18-
local source_file
19-
local source_dir=$PROJECT_ROOT/webext/dist/web-ext-artifacts
20-
local bundle_file=$PROJECT_ROOT/interfacer/src/browsh/browsh.xpi
38+
echo "Making extra copy for Goreleaser to put in Github release:"
39+
local goreleaser_pwd="$PROJECT_ROOT"/interfacer/
40+
cp -a "$source_file" "$goreleaser_pwd"
41+
ls -alh "$goreleaser_pwd"
42+
}
2143

22-
if [ "$BROWSH_ENV" == "RELEASE" ]; then
23-
# The signed version. There can only be one canonical XPI for each semantic
24-
# version.
25-
source_file="$source_dir/browsh-$version-an+fx.xpi"
44+
# It is possible to use unsigned webextensions in Firefox but it requires that Firefox
45+
# uses problematically insecure config. I know it's a hassle having to jump through all
46+
# these signing hoops, but I think it's better to use a standard Firefox configuration.
47+
# Moving away from the webextension alltogether is another story, but something I'm still
48+
# thinking about.
49+
#
50+
# NB: There can only be one canonical XPI for each semantic version.
51+
#
52+
# shellcheck disable=2120
53+
function webextension_sign() {
54+
local use_existing=$1
55+
if [ "$use_existing" == "" ]; then
2656
"$NODE_BIN"/web-ext sign --api-key "$MDN_USER" --api-secret "$MDN_KEY"
57+
_rename_built_xpi
2758
else
28-
# TODO: This doesn't currently work with the Marionettte `tempAddon`
29-
# installation method. Just use `web-ext run` and Browsh's `use-existing-ff`
30-
# flag - which is better anyway as it auto-reloads the extension when files
31-
# change. NB: If you fix this, don't forget to change the filename loaded
32-
# by `Asset()` in `main.go`.
33-
# In development/testing, we want to be able to bundle the webextension
34-
# frequently without having to resort to version bumps.
35-
source_file="$source_dir/browsh-$version.zip"
59+
echo "Skipping signing, downloading existing webextension"
60+
local base="https://github.com/browsh-org/browsh/releases/download"
61+
curl -L \
62+
-o "$(versioned_xpi_file)" \
63+
"$base/v$LATEST_TAGGED_VERSION/browsh-$LATEST_TAGGED_VERSION.xpi"
3664
fi
65+
}
3766

38-
echo "Bundling $source_file to $bundle_file"
39-
cp -f "$source_file" "$bundle_file"
67+
function _rename_built_xpi() {
68+
pushd "$XPI_SOURCE_DIR" || _panic
69+
local xpi_file
70+
xpi_file="$(
71+
find ./*.xpi \
72+
-printf "%T@ %f\n" |
73+
sort |
74+
cut -d' ' -f2 |
75+
tail -n1
76+
)"
77+
cp -a "$xpi_file" "$(versioned_xpi_file)"
78+
popd || _panic
4079
}
4180

4281
function bundle_production_webextension() {
4382
local version && version=$(browsh_version)
4483
local base='https://github.com/browsh-org/browsh/releases/download'
4584
local release_url="$base/v$version/browsh-$version-an.fx.xpi"
46-
local xpi_file=$PROJECT_ROOT/interfacer/src/browsh/browsh.xpi
47-
curl -L -o "$xpi_file" "$release_url"
85+
echo "Downloading webextension from: $release_url"
86+
local size && size=$(wc -c <"$XPI_PATH")
87+
curl -L -o "$XPI_PATH" "$release_url"
88+
if [ "$size" -lt 500 ]; then
89+
_panic "Problem downloading latest webextension XPI"
90+
fi
4891
}

0 commit comments

Comments
 (0)