Skip to content

Commit 09c22df

Browse files
committed
set up release pipeline
1 parent fdd1ead commit 09c22df

File tree

9 files changed

+265
-0
lines changed

9 files changed

+265
-0
lines changed

.github/check-needs-release.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env node
2+
3+
const getLatestRelease = async (repo) => {
4+
const response = await fetch('https://api.github.com/repos/' + repo + '/releases');
5+
if (!response.ok) throw "response is not ok";
6+
7+
const data = await response.json();
8+
if (!Array.isArray(data)) throw "invalid data";
9+
10+
return data.find(r => !r.draft && !r.prerelease);
11+
}
12+
13+
const checkNewRelease = async () => {
14+
const ublock_release = await getLatestRelease('gorhill/uBlock');
15+
const our_release = await getLatestRelease(process.env.GITHUB_REPOSITORY || 'dumbmoron/ublock-origin-crx');
16+
17+
const needs_release = !our_release || new Date(ublock_release.created_at) > new Date(our_release.created_at);
18+
const sources = ublock_release.assets.find(a => a.name.endsWith('chromium.zip'));
19+
if (needs_release && sources) {
20+
console.log('TAG_NAME=' + ublock_release.tag_name);
21+
}
22+
}
23+
24+
checkNewRelease();

.github/generate-updatexml.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
echo "<?xml version='1.0' encoding='UTF-8'?>"
4+
echo "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>"
5+
echo " <app appid='$APP_ID'>"
6+
echo " <updatecheck codebase='$DOWNLOAD_URL' version='$VERSION' />"
7+
echo " </app>"
8+
echo "</gupdate>"

.github/make-release-body.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
echo "Upstream release: https://github.com/gorhill/uBlock/releases/tag/$TAG"
4+
echo
5+
echo "Hashes:"
6+
echo '```'
7+
sha256sum *.crx
8+
echo '```'

.github/patch-update-url.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as fs from 'fs';
2+
3+
const data = JSON.parse(fs.readFileSync(process.argv[2]));
4+
5+
data.update_url = 'https://raw.githubusercontent.com/'
6+
+ (process.env.GITHUB_REPOSITORY || 'dumbmoron/ublock-origin-crx')
7+
+ '/refs/heads/main/update.xml';
8+
9+
fs.writeFileSync(process.argv[2], JSON.stringify(data, null, 2));
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Build release
2+
permissions:
3+
id-token: write
4+
attestations: write
5+
contents: write
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
release-tag:
11+
required: true
12+
description: "Upstream release tag"
13+
type: string
14+
15+
workflow_call:
16+
inputs:
17+
release-tag:
18+
required: true
19+
type: string
20+
21+
jobs:
22+
prep:
23+
runs-on: ubuntu-latest
24+
env:
25+
TAG: ${{ inputs.release-tag }}
26+
OUT_FILENAME: "uBlock0_${{ inputs.release-tag }}.crx"
27+
DIST_DIR: "./uBlock/dist/build/uBlock0.chromium"
28+
steps:
29+
- name: Checkout ublock-origin-crx
30+
uses: actions/checkout@v4
31+
- name: Checkout uBlock
32+
uses: actions/checkout@v4
33+
with:
34+
repository: gorhill/uBlock
35+
ref: ${{ inputs.release-tag }}
36+
path: uBlock
37+
- uses: pnpm/action-setup@v4
38+
- run: pnpm i --frozen-lockfile
39+
- name: Build uBlock Origin sources
40+
run: cd uBlock && make chromium
41+
- name: Patch update URL
42+
run: node .github/patch-update-url.js "$DIST_DIR/manifest.json"
43+
- name: Build .crx
44+
env:
45+
CRX3_PRIVATE_KEY: ${{ secrets.CRX3_PRIVATE_KEY }}
46+
run: |
47+
echo "$CRX3_PRIVATE_KEY" \
48+
| pnpm exec crx3 \
49+
-p /dev/stdin \
50+
-o "$OUT_FILENAME" \
51+
"$DIST_DIR/"
52+
- name: Get extension ID
53+
id: crxid
54+
run: |
55+
echo -en "crx_id=" >> $GITHUB_OUTPUT
56+
pnpm exec crx3-info < "$OUT_FILENAME" \
57+
| grep ^id \
58+
| sed 's/.* //' >> $GITHUB_OUTPUT
59+
- name: Attest
60+
uses: actions/attest-build-provenance@v2
61+
with:
62+
subject-path: ${{ env.OUT_FILENAME }}
63+
- name: Make release body
64+
run: ./.github/make-release-body.sh > release.md
65+
- name: Release
66+
uses: softprops/action-gh-release@4634c16e79c963813287e889244c50009e7f0981
67+
id: release
68+
with:
69+
body_path: ./release.md
70+
draft: false
71+
prerelease: false
72+
files: ${{ env.OUT_FILENAME }}
73+
name: ${{ inputs.release-tag }}
74+
tag_name: ${{ inputs.release-tag }}
75+
token: ${{ secrets.GITHUB_TOKEN }}
76+
- name: Update update.xml
77+
env:
78+
APP_ID: ${{ steps.crxid.outputs.crx_id }}
79+
DOWNLOAD_URL: ${{ fromJSON(steps.release.outputs.assets)[0].browser_download_url }}
80+
VERSION: ${{ inputs.release-tag }}
81+
run: |
82+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
83+
git config --local user.name "github-actions[bot]"
84+
./.github/generate-updatexml.sh > update.xml
85+
git add update.xml
86+
git commit -m 'update.xml: refresh'
87+
git push
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Check for new upstream release
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 0 * * *"
7+
8+
jobs:
9+
check:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
TAG_NAME: ${{ steps.needs-release.outputs.TAG_NAME }}
13+
steps:
14+
- name: Checkout ublock-origin-crx
15+
uses: actions/checkout@v4
16+
- uses: actions/setup-node@v3
17+
with:
18+
node-version: 20
19+
- run: ./.github/check-needs-release.js | tee -a "$GITHUB_OUTPUT"
20+
id: needs-release
21+
build:
22+
needs: check
23+
if: needs.check.outputs.TAG_NAME
24+
uses: ./.github/workflows/build-release.yml
25+
secrets: inherit
26+
with:
27+
release-tag: ${{ needs.check.outputs.TAG_NAME }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "ublock-origin-crx",
3+
"type": "module",
4+
"version": "1.0.0",
5+
"description": "",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"packageManager": "[email protected]",
11+
"author": "jj <[email protected]>",
12+
"license": "GPL-3.0",
13+
"devDependencies": {
14+
"crx3": "^1.1.3",
15+
"crx3-utils": "^0.0.3"
16+
}
17+
}

pnpm-lock.yaml

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)