Skip to content

Commit

Permalink
feat(environment) add proding environment (staging on production API)
Browse files Browse the repository at this point in the history
- introduce dedicated staging and production deploy process
- create a manifest file per env/platform
  • Loading branch information
lutangar committed Jan 24, 2020
1 parent 0aaf342 commit 152a9c2
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 150 deletions.
20 changes: 20 additions & 0 deletions .env.proding
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
BACKEND_ORIGIN=https://notices.bulles.fr/api/v3/

# Refresh intervals in minutes
REFRESH_MC_INTERVAL=300
REFRESH_CONTRIBUTORS_INTERVAL=300

UNINSTALL_ORIGIN=https://www.bulles.fr/desinstallation

# Tracking
TRACKING_URL=https://stats.lmem.net/matomo.php
TRACKING_SITE_ID=5

# Email
[email protected]
[email protected]

#SENTRY_ENABLED=true
CHROME_EXTENSION_ID=mepoelfgpameiagpkgpjphnbgampgffm
FIREFOX_EXTENSION_ID={72aad822-62f5-4663-a8f0-025b2f9a3dd5}
BABEL_ENV=production
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ [email protected]

SENTRY_ENABLED=true
CHROME_EXTENSION_ID=fpjlnlnbacohacebkadbbjebbipcknbg
FIREFOX_EXTENSION_ID=@lmem
1 change: 1 addition & 0 deletions .env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ [email protected]

#SENTRY_ENABLED=true
CHROME_EXTENSION_ID=nfabbfkbbbcebdmnocndhdombaffkaog
FIREFOX_EXTENSION_ID={7d0d2553-c311-4acd-a170-f9a4714eb2c0}
BABEL_ENV=production
11 changes: 8 additions & 3 deletions bin/web-ext-sign.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ const { getPackageDir, getPackagePath } = packageNaming;

loadEnv({ path: path.resolve() });

const { FIREFOX_API_KEY, FIREFOX_API_SECRET, NODE_ENV } = process.env;
const {
FIREFOX_API_KEY,
FIREFOX_API_SECRET,
NODE_ENV,
FIREFOX_EXTENSION_ID
} = process.env;
const { version } = pjson;

const packageDir = path.resolve(getPackageDir('firefox', NODE_ENV));
Expand All @@ -28,11 +33,11 @@ signAddon
// The explicit extension ID.
// WebExtensions do not require an ID.
// See the notes below about dealing with IDs.
// id: 'your-addon-id@somewhere',
id: FIREFOX_EXTENSION_ID,
// The release channel (listed or unlisted).
// Ignored for new add-ons, which are always unlisted.
// Default: most recently used channel.
channel: 'unlisted',
channel: NODE_ENV === 'production' ? 'listed' : 'unlisted',
// Save downloaded files to this directory.
// Default: current working directory.
downloadDir: packageDir,
Expand Down
4 changes: 2 additions & 2 deletions manifest/dev.js → manifest/development/chromium.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const csp = require('content-security-policy-builder');
const base = require('./base');
const base = require('../base');

module.exports = {
...base,
name: 'Bulles - DEV',
name: 'Bulles - development',
options_page: 'options.html',
content_security_policy: csp({
directives: {
Expand Down
4 changes: 2 additions & 2 deletions manifest/firefoxDev.js → manifest/development/firefox.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const csp = require('content-security-policy-builder');
const base = require('./base');
const base = require('../base');

module.exports = {
...base,
name: 'Bulles - DEV',
name: 'Bulles - development',
permissions: ['storage', 'tabs', '*://*/*', '<all_urls>'],
content_security_policy: csp({
directives: {
Expand Down
23 changes: 0 additions & 23 deletions manifest/getManifest.js

This file was deleted.

17 changes: 6 additions & 11 deletions manifest/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
const dev = require('./dev');
const firefoxDev = require('./firefoxDev');
const staging = require('./staging');
const chromium = require('./chromium');
const firefox = require('./firefox');
const getManifestFilepath = (env, platform) => `./${env}/${platform}.js`;

module.exports = {
dev,
staging,
chromium,
firefox,
firefoxDev
const getManifest = (env, platform) => {
console.log(getManifestFilepath(env, platform));
return JSON.stringify(require(getManifestFilepath(env, platform)), null, 2);
};

module.exports = getManifest;
22 changes: 22 additions & 0 deletions manifest/proding/chromium.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const csp = require('content-security-policy-builder');
const production = require('../production/chromium');

module.exports = {
...production,
name: 'Bulles - proding',
content_security_policy: csp({
directives: {
'default-src': ['https://notices.bulles.fr'],
'connect-src': [
'https://notices.bulles.fr',
'https://sentry.io',
'https://stats.lmem.net'
],
'script-src': ["'self'", "'unsafe-eval'"],
'object-src': ["'self'"],
'img-src': ["'self'", 'https://notices.bulles.fr', 'data:'],
'font-src': ["'self'", 'data:'],
'style-src': ["'unsafe-inline'"]
}
})
};
6 changes: 6 additions & 0 deletions manifest/proding/firefox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const production = require('../production/firefox');

module.exports = {
...production,
name: 'Bulles - proding'
};
8 changes: 6 additions & 2 deletions manifest/chromium.js → manifest/production/chromium.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
const csp = require('content-security-policy-builder');
const base = require('./base');
const base = require('../base');

module.exports = {
...base,
options_page: 'options.html',
content_security_policy: csp({
directives: {
'default-src': ['https://notices.bulles.fr'],
'connect-src': ['https://notices.bulles.fr', 'https://sentry.io', 'https://stats.lmem.net'],
'connect-src': [
'https://notices.bulles.fr',
'https://sentry.io',
'https://stats.lmem.net'
],
'script-src': ["'self'"],
'object-src': ["'self'"],
'img-src': ["'self'", 'https://notices.bulles.fr', 'data:'],
Expand Down
2 changes: 1 addition & 1 deletion manifest/firefox.js → manifest/production/firefox.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const base = require('./base');
const base = require('../base');

module.exports = {
...base,
Expand Down
32 changes: 0 additions & 32 deletions manifest/staging.js

This file was deleted.

22 changes: 22 additions & 0 deletions manifest/staging/chromium.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const csp = require('content-security-policy-builder');
const proding = require('../proding/chromium');

module.exports = {
...proding,
name: 'Bulles - staging',
content_security_policy: csp({
directives: {
'default-src': ['https://staging-notices.bulles.fr'],
'connect-src': [
'https://staging-notices.bulles.fr',
'https://sentry.io',
'https://stats.lmem.net'
],
'script-src': ["'self'", "'unsafe-eval'"],
'object-src': ["'self'"],
'img-src': ["'self'", 'https://staging-notices.bulles.fr', 'data:'],
'font-src': ["'self'", 'data:'],
'style-src': ["'unsafe-inline'"]
}
})
};
6 changes: 6 additions & 0 deletions manifest/staging/firefox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const proding = require('../proding/firefox');

module.exports = {
...proding,
name: 'Bulles - staging'
};
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
"start": "webpack --watch --progress --mode=development",
"build:staging": "yarn build:chromium --env.NODE_ENV=staging && yarn build:firefox --env.NODE_ENV=staging",
"release:staging": "yarn build:chromium --env.NODE_ENV=staging --env.SENTRY_ENABLED && yarn build:firefox --env.NODE_ENV=staging --env.SENTRY_ENABLED",
"build:proding": "yarn build:chromium --env.NODE_ENV=proding && yarn build:firefox --env.NODE_ENV=proding",
"release:proding": "yarn build:chromium --env.NODE_ENV=proding --env.SENTRY_ENABLED && yarn build:firefox --env.NODE_ENV=proding --env.SENTRY_ENABLED",
"build:firefox": "webpack --mode=production --env.PLATFORM=firefox",
"sign:firefox": "node --experimental-modules bin/web-ext-sign.mjs",
"sign:firefox:staging": "NODE_ENV=staging yarn sign:firefox",
"sign:firefox:proding": "NODE_ENV=proding yarn sign:firefox",
"upload:chrome": "node --experimental-modules bin/chrome-webstore-upload",
"upload:chrome:staging": "NODE_ENV=staging node --experimental-modules bin/chrome-webstore-upload.mjs",
"upload:chrome:proding": "NODE_ENV=proding node --experimental-modules bin/chrome-webstore-upload.mjs",
"build:chromium": "webpack --mode=production --env.PLATFORM=chromium",
"build:production": "yarn build:chromium --env.NODE_ENV=production && yarn build:firefox --env.NODE_ENV=production",
"release:production": "yarn build:chromium --env.NODE_ENV=production --env.SENTRY_ENABLED && yarn build:firefox --env.NODE_ENV=production --env.SENTRY_ENABLED",
"build": "yarn build:staging && yarn build:production",
"release": "yarn release:staging && yarn release:production",
"build": "yarn build:staging && yarn build:production && yarn build:proding",
"release": "yarn release:staging && yarn release:production && yarn build:proding",
"clean": "rm -rf build",
"test": "BACKEND_ORIGIN='' mocha -r ts-node/register -r tsconfig-paths/register -r jsdom-global/register 'src/**/*.spec.ts' 'test/app/*.ts' 'test/app/**/*.ts'",
"typecheck": "tsc --noEmit",
Expand All @@ -28,7 +32,9 @@
"verify": "yarn test && yarn typecheck && yarn lint",
"analyze": "webpack --mode=production --env.NODE_ENV=production --env.PLATFORM=chromium --env.ANALYZE",
"storybook": "start-storybook --ci -p 6007 -c .storybook",
"build-storybook": "build-storybook"
"build-storybook": "build-storybook",
"deploy": "DEPLOY=staging yarn semantic-release --dry-run",
"deploy:production": "DEPLOY=production yarn semantic-release --dry-run"
},
"husky": {
"hooks": {
Expand Down
83 changes: 13 additions & 70 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,16 @@
const { getPackagePath } = require('./webpack/packageNaming');
const { DEPLOY } = process.env;

const release = Object.freeze({
verifyConditions: [
'@semantic-release/changelog',
'@semantic-release/git',
'@semantic-release/github',
'semantic-release-chrome'
],
analyzeCommits: {
preset: 'angular',
parserOpts: {
noteKeywords: ['BREAKING CHANGE', 'BREAKING CHANGES', 'MAJOR RELEASE']
}
},
prepare: [
'@semantic-release/changelog',
{
path: '@semantic-release/exec',
cmd:
'sed -i -r \'s/"version":\\s*"[^"]+"/"version": "${nextRelease.version}"/\' package.json'
},
{
path: '@semantic-release/git',
assets: ['package.json', 'yarn.lock', 'CHANGELOG.md'],
message:
'chore: release ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}'
}
],
publish: [
{
path: '@semantic-release/exec',
cmd: 'yarn run release'
},
{
path: '@semantic-release/exec',
cmd: 'yarn run sign:firefox:staging'
},
{
path: '@semantic-release/exec',
cmd: 'yarn run upload:chrome:staging'
},
{
path: '@semantic-release/github',
assets: [
{
path: getPackagePath('*', 'firefox', 'staging'),
label: 'Firefox Package - staging'
},
{
path: getPackagePath('*', 'firefox', 'production'),
label: 'Firefox Package'
},
{
path: getPackagePath('*', 'chromium', 'staging'),
label: 'Chromium Package - staging'
},
{
path: getPackagePath('*', 'chromium', 'production'),
label: 'Chromium Package'
}
]
}
//FIXME: semantic-release-chrome does not take globs on assets pathnames
//{
// path: 'semantic-release-chrome',
// asset: 'build/bulles-v*-chromium.zip',
// extensionId: 'fpjlnlnbacohacebkadbbjebbipcknbg',
//},
]
const getLogger = require('semantic-release/lib/get-logger');

const logger = getLogger({
cwd: process.cwd(),
env: process.env,
stdout: process.stdout,
stderr: process.stderr
});

module.exports = release;
const configFilePath = `./release.config.${DEPLOY}.js`;

logger.log(`Loading config file ${configFilePath}`);

module.exports = require(configFilePath);
Loading

0 comments on commit 152a9c2

Please sign in to comment.