Skip to content

Commit 16d4b5b

Browse files
Merge pull request #105 from CyberDrain/dev
Dev
2 parents 638c177 + e261c9a commit 16d4b5b

38 files changed

+3495
-957
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Assumes that:
2+
# 1. the following env variables are set:
3+
# - ZIP_FILE_PATH
4+
# - EXTENSION_DIR
5+
# 2. repository checked out
6+
# Effects:
7+
# - builds and tests an extension, fails on error
8+
# - packed extension.zip saved to env.ZIP_FILE_PATH if inputs.doNotPackZip == 'false'
9+
10+
name: "Build, test and pack WebExtension"
11+
description: "Builds, tests, and packs extension dir into zip file"
12+
13+
inputs:
14+
doNotPackZip:
15+
description: 'Set `true` to omit pack step'
16+
required: false
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
# Add additional build and test steps here
22+
23+
- name: Copy extension to folder
24+
shell: bash
25+
run: |
26+
mkdir -p ${{ env.EXTENSION_DIR }}
27+
cp manifest.json ${{ env.EXTENSION_DIR }}
28+
cp blocked.html ${{ env.EXTENSION_DIR }}
29+
cp -r config/ ${{ env.EXTENSION_DIR }}
30+
cp -r images/ ${{ env.EXTENSION_DIR }}
31+
cp -r options/ ${{ env.EXTENSION_DIR }}
32+
cp -r popup/ ${{ env.EXTENSION_DIR }}
33+
cp -r rules/ ${{ env.EXTENSION_DIR }}
34+
cp -r scripts/ ${{ env.EXTENSION_DIR }}
35+
cp -r styles/ ${{ env.EXTENSION_DIR }}
36+
37+
- name: Pack directory to zip
38+
if: inputs.doNotPackZip != 'true'
39+
uses: cardinalby/webext-buildtools-pack-extension-dir-action@28fdcac9860fb08555580587cab0d33afe4a341d
40+
with:
41+
extensionDir: ${{ env.EXTENSION_DIR }}
42+
zipFilePath: ${{ env.ZIP_FILE_PATH }}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Assumes that:
2+
# 1. the following env variables are set:
3+
# - ZIP_ASSET_NAME
4+
# - ZIP_FILE_PATH
5+
# - ZIP_FILE_NAME
6+
# - EXTENSION_DIR
7+
# 2. repository checked out
8+
# Effects:
9+
# - extension.zip saved to env.ZIP_FILE_PATH
10+
# - outputs.releaseUploadUrl is set if ref_type == 'tag' and release exists
11+
# - extension.zip uploaded as build artifact to the job if it wasn't found in release
12+
13+
name: "Obtain extension.zip asset"
14+
description: "Downloads zip asset from a release (if exists) or builds it from the scratch"
15+
inputs:
16+
githubToken:
17+
description: GitHub token
18+
required: true
19+
outputs:
20+
releaseUploadUrl:
21+
description: Release upload url, if exists
22+
value: ${{ steps.getRelease.outputs.upload_url }}
23+
runs:
24+
using: "composite"
25+
steps:
26+
- name: Get release
27+
id: getRelease
28+
if: github.ref_type == 'tag'
29+
uses: cardinalby/git-get-release-action@cedef2faf69cb7c55b285bad07688d04430b7ada
30+
env:
31+
GITHUB_TOKEN: ${{ inputs.githubToken }}
32+
with:
33+
tag: ${{ github.ref_name }}
34+
doNotFailIfNotFound: true
35+
36+
- name: Find out zip asset id from assets JSON
37+
if: steps.getRelease.outputs.assets
38+
id: readAssetIdFromRelease
39+
uses: cardinalby/js-eval-action@b34865f1d9cfdf35356013627474857cfe0d5091
40+
env:
41+
ASSETS_JSON: ${{ steps.getRelease.outputs.assets }}
42+
ASSET_NAME: ${{ env.ZIP_ASSET_NAME }}
43+
with:
44+
expression: |
45+
JSON.parse(env.ASSETS_JSON)
46+
.find(asset => asset.name == env.ZIP_ASSET_NAME)?.id || ''
47+
48+
- name: Download found zip release asset
49+
id: downloadZipAsset
50+
if: steps.readAssetIdFromRelease.outputs.result
51+
uses: cardinalby/download-release-asset-action@8fe4ec3a876fe25b72086c8de1faddfaeb6512ff
52+
with:
53+
token: ${{ inputs.githubToken }}
54+
assetId: ${{ steps.readAssetIdFromRelease.outputs.result }}
55+
targetPath: ${{ env.ZIP_FILE_PATH }}
56+
57+
- name: Build and pack zip
58+
id: buildZip
59+
if: steps.downloadZipAsset.outcome != 'success'
60+
uses: ./.github/workflows/actions/build-test-pack
61+
62+
- name: Upload zip file artifact
63+
if: steps.buildZip.outcome == 'success'
64+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
65+
with:
66+
name: ${{ env.ZIP_FILE_NAME }}
67+
path: ${{ env.ZIP_FILE_PATH }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build and test
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- 'main'
7+
- 'dev'
8+
workflow_dispatch:
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: cardinalby/export-env-action@66657b34899a2d695434ed060d9f2215db9b4035
16+
with:
17+
envFile: './.github/workflows/constants.env'
18+
expand: true
19+
20+
- name: Build, test and pack to zip
21+
id: build
22+
uses: ./.github/workflows/actions/build-test-pack
23+
with:
24+
# pack zip only for pull requests or workflow_dispatch events
25+
doNotPackZip: ${{ github.event_name == 'push' && 'true' || 'false'}}
26+
27+
- name: Upload zip file artifact
28+
if: github.event_name != 'push'
29+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
30+
with:
31+
name: ${{ env.ZIP_FILE_NAME }}
32+
path: ${{ env.ZIP_FILE_PATH }}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# On release published:
2+
# - if no built extension.zip asset attached to release, does that
3+
# - builds and attaches signed crx asset to release
4+
# - builds and attaches signed xpi asset to release
5+
name: Build release assets
6+
7+
on:
8+
release:
9+
# Creating draft releases will not trigger it
10+
types: [published]
11+
jobs:
12+
# Find out asset id of existing extension.zip asset in a release or
13+
# build and attach it to the release and use its asset id
14+
ensure-zip:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
zipAssetId: |
18+
${{ steps.getZipAssetId.outputs.result ||
19+
steps.uploadZipAsset.outputs.id }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- uses: cardinalby/export-env-action@66657b34899a2d695434ed060d9f2215db9b4035
24+
with:
25+
envFile: './.github/workflows/constants.env'
26+
expand: true
27+
28+
- name: Find out "extension.zip" asset id from the release
29+
id: getZipAssetId
30+
uses: cardinalby/js-eval-action@b34865f1d9cfdf35356013627474857cfe0d5091
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
ASSETS_URL: ${{ github.event.release.assets_url }}
34+
ASSET_NAME: ${{ env.ZIP_FILE_NAME }}
35+
with:
36+
expression: |
37+
(await octokit.request("GET " + env.ASSETS_URL)).data
38+
.find(asset => asset.name == env.ASSET_NAME)?.id || ''
39+
40+
- name: Build, test and pack
41+
if: '!steps.getZipAssetId.outputs.result'
42+
id: buildPack
43+
uses: ./.github/workflows/actions/build-test-pack
44+
45+
- name: Upload "extension.zip" asset to the release
46+
id: uploadZipAsset
47+
if: '!steps.getZipAssetId.outputs.result'
48+
uses: actions/upload-release-asset@v1
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
with:
52+
upload_url: ${{ github.event.release.upload_url }}
53+
asset_path: ${{ env.ZIP_FILE_PATH }}
54+
asset_name: ${{ env.ZIP_FILE_NAME }}
55+
asset_content_type: application/zip
56+
57+
build-signed-crx-asset:
58+
needs: ensure-zip
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v4
62+
63+
- uses: cardinalby/export-env-action@66657b34899a2d695434ed060d9f2215db9b4035
64+
with:
65+
envFile: './.github/workflows/constants.env'
66+
expand: true
67+
68+
- name: Download zip release asset
69+
uses: cardinalby/download-release-asset-action@8fe4ec3a876fe25b72086c8de1faddfaeb6512ff
70+
with:
71+
token: ${{ secrets.GITHUB_TOKEN }}
72+
assetId: ${{ needs.ensure-zip.outputs.zipAssetId }}
73+
targetPath: ${{ env.ZIP_FILE_PATH }}
74+
75+
- name: Build offline crx
76+
id: buildOfflineCrx
77+
uses: cardinalby/webext-buildtools-chrome-crx-action@200e7173cbdb5acb91d381cf9f7a30080b025047
78+
with:
79+
zipFilePath: ${{ env.ZIP_FILE_PATH }}
80+
crxFilePath: ${{ env.OFFLINE_CRX_FILE_PATH }}
81+
privateKey: ${{ secrets.CHROME_CRX_PRIVATE_KEY }}
82+
83+
- name: Upload offline crx release asset
84+
uses: actions/upload-release-asset@v1
85+
env:
86+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87+
with:
88+
upload_url: ${{ github.event.release.upload_url }}
89+
asset_path: ${{ env.OFFLINE_CRX_FILE_PATH }}
90+
asset_name: ${{ env.OFFLINE_CRX_FILE_NAME }}
91+
asset_content_type: application/x-chrome-extension

.github/workflows/constants.env

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
EXTENSION_DIR=extension/
2+
BUILD_DIR=build/
3+
4+
ZIP_FILE_NAME=extension.zip
5+
ZIP_FILE_PATH=${BUILD_DIR}${ZIP_FILE_NAME}
6+
7+
WEBSTORE_CRX_FILE_NAME=extension.webstore.crx
8+
WEBSTORE_CRX_FILE_PATH=${BUILD_DIR}${WEBSTORE_CRX_FILE_NAME}
9+
10+
OFFLINE_CRX_FILE_NAME=extension.offline.crx
11+
OFFLINE_CRX_FILE_PATH=${BUILD_DIR}${OFFLINE_CRX_FILE_NAME}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Google Refresh Token
2+
on:
3+
schedule:
4+
- cron: '0 3 2 * *' # At 03:00 on day-of-month 2
5+
workflow_dispatch:
6+
jobs:
7+
fetchToken:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: cardinalby/google-api-fetch-token-action@24c99245e2a2494cc4c4b1037203d319a184b15b
11+
with:
12+
clientId: ${{ secrets.G_CLIENT_ID }}
13+
clientSecret: ${{ secrets.G_CLIENT_SECRET }}
14+
refreshToken: ${{ secrets.G_REFRESH_TOKEN }}

.github/workflows/pr_check.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: PR Branch Check
2+
3+
on:
4+
# Using pull_request_target instead of pull_request for secure handling of fork PRs
5+
pull_request_target:
6+
# Only run on these PR events
7+
types: [opened, synchronize, reopened]
8+
# Only check PRs targeting these branches
9+
branches:
10+
- main
11+
- master
12+
13+
permissions:
14+
pull-requests: write
15+
issues: write
16+
17+
jobs:
18+
check-branch:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check and Comment on PR
22+
# Only process fork PRs with specific branch conditions
23+
# Must be a fork AND (source is main/master OR target is main/master)
24+
if: |
25+
github.event.pull_request.head.repo.fork == true &&
26+
((github.event.pull_request.head.ref == 'main' || github.event.pull_request.head.ref == 'master') ||
27+
(github.event.pull_request.base.ref == 'main' || github.event.pull_request.base.ref == 'master'))
28+
uses: actions/github-script@v7
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
script: |
32+
let message = '';
33+
34+
// Check if PR is targeting main/master
35+
if (context.payload.pull_request.base.ref === 'main' || context.payload.pull_request.base.ref === 'master') {
36+
message += '⚠️ PRs cannot target the main branch directly. If you are attempting to contribute code please PR to the dev branch.\n\n';
37+
}
38+
39+
// Check if PR is from a fork's main/master branch
40+
if (context.payload.pull_request.head.repo.fork &&
41+
(context.payload.pull_request.head.ref === 'main' || context.payload.pull_request.head.ref === 'master')) {
42+
message += '⚠️ This PR cannot be merged because it originates from your fork\'s main/master branch. If you are attempting to contribute code please PR from your dev branch or another non-main/master branch.\n\n';
43+
}
44+
45+
message += '🔒 This PR will now be automatically closed due to the above rules.';
46+
47+
// Post the comment
48+
await github.rest.issues.createComment({
49+
...context.repo,
50+
issue_number: context.issue.number,
51+
body: message
52+
});
53+
54+
// Close the PR
55+
await github.rest.pulls.update({
56+
...context.repo,
57+
pull_number: context.issue.number,
58+
state: 'closed'
59+
});

0 commit comments

Comments
 (0)