Github action and creation scripts

This commit is contained in:
Andrea Marchesini 2021-10-26 14:00:53 +02:00
parent 5c12e58cd7
commit 83687f6324
7 changed files with 154 additions and 10 deletions

30
.github/workflows/builds.yaml vendored Normal file
View file

@ -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

2
.gitmodules vendored
View file

@ -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

View file

@ -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)

35
bin/addons-linter.sh Executable file
View file

@ -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

View file

@ -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

54
bin/commons.sh Normal file
View file

@ -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
}

View file

@ -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 .",