Skip to content

Commit a101e68

Browse files
committed
fix the chrome & firefox release pipeline
1 parent e98f457 commit a101e68

12 files changed

Lines changed: 219 additions & 112 deletions

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ jobs:
1919
cd ~/hackertab.dev
2020
git pull origin master
2121
yarn
22-
yarn web-build
22+
yarn build-web

.github/workflows/distribute.yml

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,104 @@
1-
# Deploy the extension to Chrome and firefox web stores
2-
# when creating a new release
3-
4-
name: Deploy to web stores
1+
name: Publish extension to Chrome and Firefox
52

63
on:
7-
release:
8-
types:
9-
- created
4+
workflow_dispatch:
5+
inputs:
6+
targetStore:
7+
description: 'Store target'
8+
required: true
9+
default: 'all'
10+
type: choice
11+
options:
12+
- chrome
13+
- firefox
14+
- all
15+
autoTag:
16+
description: 'Auto Create a new tag'
17+
required: true
18+
default: true
19+
type: boolean
20+
testMode:
21+
description: 'Test Mode'
22+
required: true
23+
default: false
24+
type: boolean
1025
env:
11-
REACT_APP_BUILD_TARGET: "extension"
26+
REACT_APP_BUILD_TARGET: 'extension'
27+
1228
jobs:
13-
14-
bump-manifest-version:
29+
install-dependencies:
30+
needs: tag_version
1531
runs-on: ubuntu-latest
16-
1732
steps:
1833
- uses: actions/checkout@v2
1934
with:
2035
ref: master
21-
2236
- uses: actions/cache@v2
2337
with:
2438
path: '**/node_modules'
25-
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
26-
27-
- name: Install json globaly
28-
run: yarn global add json
29-
30-
# clean release name (as used as version)
31-
- name: Clean release name
32-
id: clean
33-
run: echo ::set-output name=version::$(echo ${{github.event.release.tag_name }} | sed 's/[^0-9.]//g')
34-
35-
# Update manifest version
36-
- name: Update manifest version
37-
run: json -I -f public/manifest.json -e 'this.version="${{ steps.clean.outputs.version }}"'
39+
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
40+
- name: Install yarn dependencies
41+
run: yarn
42+
- name: Build and zip the extension
43+
run: |
44+
echo version=${{ steps.tag_version.outputs.new_version }}
45+
if [ ${{github.event.inputs.targetStore}} == 'chrome' ] || [ ${{github.event.inputs.targetStore}} == 'all' ]; then
46+
yarn build-chrome
47+
fi
48+
if [ ${{github.event.inputs.targetStore}} == 'firefox' ] || [ ${{github.event.inputs.targetStore}} == 'all' ]; then
49+
yarn build-firefox
50+
fi
3851
39-
# Commit changes
52+
tag_version:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v2
56+
- name: Bump version and push tag
57+
id: tag_version
58+
uses: mathieudutour/github-tag-action@v6.1
59+
with:
60+
github_token: ${{ secrets.GITHUB_TOKEN }}
61+
dry_run: ${{ github.event.inputs.testMode == 'true' }}
62+
63+
- name: Update manifest.json
64+
if: github.event.inputs.autoTag == 'true'
65+
run: jq --arg version "${{ steps.tag_version.outputs.new_version }}" '.version=$version' public/base.manifest.json > tmp.json && mv tmp.json public/base.manifest.json
66+
4067
- name: Commit changes
68+
if: github.event.inputs.autoTag == 'true'
4169
uses: EndBug/add-and-commit@v5
4270
with:
4371
branch: master
44-
author_name: Bot Driyaf
72+
author_name: Github bot
4573
author_email: elmehdi.sakout@gmail.com
4674
message: "Bump manifest version"
47-
48-
build-extension:
49-
needs: bump-manifest-version
75+
76+
chrome-deploy:
77+
if: ${{ (github.event.inputs.targetStore == 'chrome') || (github.event.inputs.targetStore == 'all') }}
78+
needs: install-dependencies
5079
runs-on: ubuntu-latest
51-
steps:
52-
- uses: actions/checkout@v2
53-
with:
54-
ref: master
55-
56-
- uses: actions/cache@v2
57-
with:
58-
path: '**/node_modules'
59-
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
60-
61-
- name: Install yarn dependencies
62-
run: yarn
63-
64-
- name: Build and zip the extension
65-
run: yarn stores-build
66-
67-
- name: Install chrome & FF web stores dependencies
68-
run: yarn global add chrome-webstore-upload-cli web-ext web-ext-submit@6
80+
steps:
81+
- name: Install chrome dependencies
82+
run: yarn global add chrome-webstore-upload-cli
6983

7084
- name: Upload the package to Chrome web store
85+
if: ${{ github.event.inputs.testMode == 'false' }}
7186
env:
7287
EXTENSION_ID: ${{ secrets.CHROME_EXTENSION_ID }}
7388
CLIENT_ID: ${{secrets.CHROME_EXTENSION_CLIENT_ID}}
7489
REFRESH_TOKEN: ${{secrets.CHROME_EXTENSION_REFRESH_TOKEN}}
7590
run: chrome-webstore-upload upload --source dist/chrome_extension.zip --extension-id $EXTENSION_ID --auto-publish
91+
92+
firefox-deploy:
93+
if: ${{ (github.event.inputs.targetStore == 'firefox') || (github.event.inputs.targetStore == 'all') }}
94+
needs: install-dependencies
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Install Firefox dependencies
98+
run: yarn global add web-ext web-ext-submit@6
7699

77100
- name: Upload the package to Firefox web store
101+
if: ${{ github.event.inputs.testMode == 'false' }}
78102
env:
79103
WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }}
80104
WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ npm-debug.log*
2626
yarn-debug.log*
2727
yarn-error.log*
2828
TODO
29+
jq

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444
"proxy": "https://api.hackertab.dev/",
4545
"scripts": {
4646
"start": "craco start",
47-
"web-build": "craco --max_old_space_size=4096 build",
47+
"build-web": "craco --max_old_space_size=4096 build",
4848
"build": "./script/build.sh",
49-
"stores-build": "./script/stores_build.sh",
49+
"build-firefox": "./script/build-firefox.sh",
50+
"build-chrome": "./script/build-chrome.sh",
5051
"eject": "react-scripts eject"
5152
},
5253
"eslintConfig": {

public/base.manifest.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "Hackertab.dev - developer news",
3+
"description": "All developer news in one tab",
4+
"version": "1.15.2",
5+
"chrome_url_overrides": {
6+
"newtab": "index.html"
7+
}
8+
}

public/chrome.manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"manifest_version": 3,
3+
"background": {
4+
"service_worker": "background.js"
5+
},
6+
"host_permissions": ["https://*.hackertab.dev/*"]
7+
}

public/firefox.manifest.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"manifest_version": 2,
3+
"background": {
4+
"scripts": [
5+
"background.js"
6+
]
7+
},
8+
"permissions": [
9+
"https://*.hackertab.dev/*"
10+
],
11+
"content_security_policy": "script-src 'self' object-src 'self'",
12+
"applications": {
13+
"gecko": {
14+
"id": "{f8793186-e9da-4332-aa1e-dc3d9f7bb04c}"
15+
}
16+
}
17+
}

public/manifest.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
{
22
"name": "Hackertab.dev - developer news",
33
"description": "All developer news in one tab",
4-
"version": "1.15.2",
5-
"manifest_version": 3,
4+
"version": "1.2.3",
65
"chrome_url_overrides": {
76
"newtab": "index.html"
87
},
8+
"manifest_version": 3,
99
"background": {
1010
"service_worker": "background.js"
1111
},
12-
"host_permissions": ["https://*.hackertab.dev/*"],
13-
"icons": {
14-
"16": "/logos/logo16.png",
15-
"32": "/logos/logo32.png",
16-
"48": "/logos/logo48.png",
17-
"128": "/logos/logo128.png"
18-
}
12+
"host_permissions": [
13+
"https://*.hackertab.dev/*"
14+
]
1915
}

public/web_manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"short_name": "Hackertab.dev",
3-
"name": "The Developer’s Homepage",
4-
"description": "Hackertab helps developers stay up-to-date with the latest tech happenings",
3+
"name": "All developer news in one tab",
4+
"description": "Hackertab helps developers stay up-to-date with the latest dev trends and tools",
55
"icons": [
66
{
77
"src": "/logos/logoVector.svg",

script/build-chrome.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
echo 'building extension for Chrome...'
2+
3+
# install jq if not installed
4+
if ! command -v jq &> /dev/null
5+
then
6+
echo "jq command not found. attempting to download jq binary"
7+
pth=$(pwd)
8+
export PATH=$PATH:$pth
9+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
10+
curl -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -o jq
11+
elif [[ "$OSTYPE" == "darwin"* ]]; then
12+
curl -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 -o jq
13+
else
14+
echo "Unsupported OS type. Exiting..."
15+
exit 1
16+
fi
17+
chmod +x jq
18+
fi
19+
20+
# Merge base and chrome jsons
21+
if [ -n "$version" ]; then
22+
echo "Change manifest version to ${version}"
23+
jq ".version = \"$version\"" ./public/base.manifest.json > base.manifest.temp.json
24+
echo 'Generate Chrome manifest'
25+
jq -s '.[0] * .[1]' base.manifest.temp.json ./public/chrome.manifest.json > ./public/manifest.json
26+
rm -f base.manifest.temp.json
27+
else
28+
echo 'Generate Chrome manifest'
29+
jq -s '.[0] * .[1]' ./public/base.manifest.json ./public/chrome.manifest.json > ./public/manifest.json
30+
fi
31+
32+
# Remove previous artifacts
33+
echo 'Remove previous zipped extension'
34+
rm -f chrome_extension.zip
35+
36+
# Install dependencies
37+
echo 'Install dependencies'
38+
yarn build
39+
40+
# Copy generated build to distrubution folder
41+
echo 'Copy generated build to distrubution folder'
42+
mkdir -p dist
43+
cp -r build/* dist
44+
45+
# Zip the distribution folder
46+
echo 'Zip the extension'
47+
cd dist/ && zip -r ../chrome_extension.zip * -x "*.DS_Store" && cd ..

0 commit comments

Comments
 (0)