From 83687f63246e93400cc52d1cd6b854c949d40a3b Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Tue, 26 Oct 2021 14:00:53 +0200 Subject: [PATCH] Github action and creation scripts --- .github/workflows/builds.yaml | 30 +++++++++++++++++++ .gitmodules | 2 ++ README.md | 18 +++++++----- bin/addons-linter.sh | 35 +++++++++++++++++++++++ bin/build-addon.sh | 22 +++++++++++++- bin/commons.sh | 54 +++++++++++++++++++++++++++++++++++ package.json | 3 +- 7 files changed, 154 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/builds.yaml create mode 100755 bin/addons-linter.sh create mode 100644 bin/commons.sh diff --git a/.github/workflows/builds.yaml b/.github/workflows/builds.yaml new file mode 100644 index 0000000..3d3cd1e --- /dev/null +++ b/.github/workflows/builds.yaml @@ -0,0 +1,30 @@ +name: Builds +on: + push: + branches: + - main + - production + pull_request: + branches: + - main + - production + +jobs: + builds: + name: Builds + runs-on: ubuntu-20.04 + + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Create the package + shell: bash + run: | + ./bin/build-addon.sh + + - name: Uploading + uses: actions/upload-artifact@v1 + with: + name: ${{matrix.config.name}} Build + path: src/web-ext-artifacts diff --git a/.gitmodules b/.gitmodules index cab4edf..acf9a70 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,5 @@ [submodule "src/_locales"] + branch = main path = src/_locales url = https://github.com/mozilla-l10n/multi-account-containers-l10n.git + ignore=all diff --git a/README.md b/README.md index 4123b0e..5265dfc 100644 --- a/README.md +++ b/README.md @@ -22,17 +22,19 @@ For more info, see: #### Via WebExtensions API (web-ext) -1. Install the [web-ext](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Getting_started_with_web-ext) tool. -2. Run `web-ext run -s src/`. This launches Firefox and installs the extension automatically. +1. Fetch the locales updating the git-submodules: `git submodule init && git submodule update --remote --depth 1 src/_locales` +2. Install the [web-ext](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Getting_started_with_web-ext) tool. +3. Run `web-ext run -s src/`. This launches Firefox and installs the extension automatically. This tool provides some additional development features, such as [automatic reloading](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Getting_started_with_web-ext#Automatic_extension_reloading). #### Via about:debugging in Firefox -1. Open the `about:debugging` page in Firefox. -2. Click on `This Firefox`. -3. Click on [Load Temporary Add-on](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Temporary_Installation_in_Firefox). -4. Select `src/manifest.json`. +1. Fetch the locales updating the git-submodules: `git submodule init && git submodule update --remote --depth 1 src/_locales` +2. Open the `about:debugging` page in Firefox. +3. Click on `This Firefox`. +4. Click on [Load Temporary Add-on](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Temporary_Installation_in_Firefox). +5. Select `src/manifest.json`. Here is a [video](https://www.youtube.com/watch?v=cer9EUKegG4) that demonstrates how to do this. @@ -59,6 +61,7 @@ Here is a [video](https://www.youtube.com/watch?v=cer9EUKegG4) that demonstrates There is a timeout test that sometimes fails on certain machines, so make sure to run the tests on your clone before you make any changes to see if you have this problem. #### Add/update messages for translation + The `src/_locales` directory is a git repository like any other, so to make changes to the messages: 1. Make whatever changes you need in `src/_locales/en` as you work. @@ -83,10 +86,11 @@ You can then open a pull request from the `message-updates-yyyymmdd` branch to #### Publish to AMO -1. `npm run-script build` +1. `./bin/build-addon.sh` 2. [Upload the `.zip` to AMO](https://addons.mozilla.org/developers/addon/multi-account-containers/versions/submit/) #### Publish to GitHub + Finally, we also publish the release to GitHub for those followers. 1. Download the signed `.xpi` from [the addon versions page](https://addons.mozilla.org/developers/addon/multi-account-containers/versions) diff --git a/bin/addons-linter.sh b/bin/addons-linter.sh new file mode 100755 index 0000000..0038efe --- /dev/null +++ b/bin/addons-linter.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# addons-linter is not happy to see a `.github` folder in src/_locales. +# We need to do an horrible hack to run the test. + +. $(dirname $0)/commons.sh + +TMPDIR=/tmp/MAC_addonsLinter + +print Y "Update the submodules..." +git submodule init || die +git submodule update --remote --depth 1 src/_locales || die + +printn Y "Removing previous execution data... " +rm -rf $TMPDIR || die +print G "done." + +printn Y "Creating a tmp folder ($TMPDIR)... " +mkdir $TMPDIR || die +print G "done." + +printn Y "Copying data... " +cp -r src $TMPDIR || die +print G "done." + +printn Y "Removing the github folder... " +rm -rf $TMPDIR/src/_locales/.github || die +print G "done." + +print Y "Running the test..." +$(npm bin)/addons-linter $TMPDIR/src || die diff --git a/bin/build-addon.sh b/bin/build-addon.sh index 5cd94f2..afb5b84 100755 --- a/bin/build-addon.sh +++ b/bin/build-addon.sh @@ -1 +1,21 @@ -npm install && npm run deploy +#!/bin/bash + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +. $(dirname $0)/commons.sh + +print Y "Update the submodules..." +git submodule init || die +git submodule update --remote --depth 1 src/_locales || die + +print Y "Installing dependencies..." +npm install || die + +print Y "Running tests..." +npm test + +print Y "Creating the final package..." +cd src || die +$(npm bin)/web-ext build --overwrite-dest || die diff --git a/bin/commons.sh b/bin/commons.sh new file mode 100644 index 0000000..d893510 --- /dev/null +++ b/bin/commons.sh @@ -0,0 +1,54 @@ +#!/bin/bash + +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +printv() { + if [ -t 1 ]; then + NCOLORS=$(tput colors) + + if test -n "$NCOLORS" && test "$NCOLORS" -ge 8; then + NORMAL="$(tput sgr0)" + RED="$(tput setaf 1)" + GREEN="$(tput setaf 2)" + YELLOW="$(tput setaf 3)" + fi + fi + + if [[ $2 = 'G' ]]; then + # shellcheck disable=SC2086 + echo $1 -e "${GREEN}$3${NORMAL}" + elif [[ $2 = 'Y' ]]; then + # shellcheck disable=SC2086 + echo $1 -e "${YELLOW}$3${NORMAL}" + elif [[ $2 = 'N' ]]; then + # shellcheck disable=SC2086 + echo $1 -e "$3" + else + # shellcheck disable=SC2086 + echo $1 -e "${RED}$3${NORMAL}" + fi +} + +print() { + printv '' "$1" "$2" +} + +printn() { + printv "-n" "$1" "$2" +} + +error() { + printv '' R "$1" +} + +die() { + if [[ "$1" ]]; then + error "$1" + else + error Failed + fi + + exit 1 +} diff --git a/package.json b/package.json index 9e767a4..6ed7be8 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,9 @@ "url": "git+https://github.com/mozilla/multi-account-containers.git" }, "scripts": { - "build": "npm test && cd src && web-ext build --overwrite-dest", "webext": "web-ext run -s src/", "lint": "npm-run-all lint:*", - "lint:addon": "addons-linter src --self-hosted", + "lint:addon": "./bin/addons-linter.sh", "lint:css": "stylelint src/css/*.css", "lint:html": "htmllint *.html", "lint:js": "eslint .",