Skip to content

Conversation

@seia-soto
Copy link
Member

Unattended pull creation by checking regularly.

@seia-soto seia-soto self-assigned this May 21, 2025
@seia-soto seia-soto requested a review from chrmod May 21, 2025 04:57
Copy link
Member

@chrmod chrmod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please inline the bash script

@seia-soto seia-soto requested a review from chrmod May 21, 2025 08:11
@seia-soto
Copy link
Member Author

We'll need to:

  • reconfigure adblocker bot access to this repository

Comment on lines 20 to 55
function gh_repo_tags() {
# REPO_REF="owner/repo"
local REPO_REF="$1"
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-tags
curl -sL \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$REPO_REF/tags"
}

function gh_repo_latest_tagname() {
# REPO_REF="owner/repo"
local REPO_REF="$1"
gh_repo_tags "$REPO_REF" | \
jq -r '.[].name | select(test("^[0-9]"))' | \
sort -Vr | \
head -1
}

function get_local_tagname() {
# deno build.ts --tagName 1.64.0 > ubo.js
cat 'package.json' | sed -n -E 's/.*--tagName ([0-9\.a-zA-Z]+).*/\1/p'
}

LOCAL_REF="$(get_local_tagname)"
UPSTREAM_REF="$(gh_repo_latest_tagname 'gorhill/ublock')"
if [[ "$UPSTREAM_REF" == 'null' ]]; then
echo "ERROR: Failed to retrieve upstream version! Run with 'set -xe' for debugging."
exit 1
fi
if [[ "$(echo "$LOCAL_REF\n$UPSTREAM_REF" | sort -Vr | head -1)" != "$LOCAL_REF" ]]; then
NEW_TAGNAME="$1"
cat 'package.json' | sed -E "s/(--tagName )([0-9\.a-zA-Z]+)/\1$NEW_TAGNAME/" | tee 'package.json'
deno run build
fi

Copy link
Member

@chrmod chrmod May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function gh_repo_tags() {
# REPO_REF="owner/repo"
local REPO_REF="$1"
# https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#list-repository-tags
curl -sL \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$REPO_REF/tags"
}
function gh_repo_latest_tagname() {
# REPO_REF="owner/repo"
local REPO_REF="$1"
gh_repo_tags "$REPO_REF" | \
jq -r '.[].name | select(test("^[0-9]"))' | \
sort -Vr | \
head -1
}
function get_local_tagname() {
# deno build.ts --tagName 1.64.0 > ubo.js
cat 'package.json' | sed -n -E 's/.*--tagName ([0-9\.a-zA-Z]+).*/\1/p'
}
LOCAL_REF="$(get_local_tagname)"
UPSTREAM_REF="$(gh_repo_latest_tagname 'gorhill/ublock')"
if [[ "$UPSTREAM_REF" == 'null' ]]; then
echo "ERROR: Failed to retrieve upstream version! Run with 'set -xe' for debugging."
exit 1
fi
if [[ "$(echo "$LOCAL_REF\n$UPSTREAM_REF" | sort -Vr | head -1)" != "$LOCAL_REF" ]]; then
NEW_TAGNAME="$1"
cat 'package.json' | sed -E "s/(--tagName )([0-9\.a-zA-Z]+)/\1$NEW_TAGNAME/" | tee 'package.json'
deno run build
fi
#!/usr/bin/env bash
set -euo pipefail
upstream_tag=$(curl -s https://api.github.com/repos/gorhill/ublock/releases/latest \
| jq -r .tag_name)
if [[ "$upstream_tag" == null ]]; then
echo "ERROR: could not fetch upstream tag"
exit 1
fi
local_tag=$(sed -nEn 's/.*--tagName ([0-9.]+).*/\1/p' package.json)
if [[ "$upstream_tag" != "$local_tag" ]]; then
sed -i -E "s/--tagName [0-9.]+/--tagName $upstream_tag/" package.json
deno run build
fi

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored in 01df394 but leaving some notes

  • Kept regex patterns as new regexp don't support all cases e.g. 1.64.1b0
  • Kept the form of cat ... | sed ... | tee ... instead of sed in-place modification for straightforward compatibility with bsd sed (for direct macOS testing without any confusion)
  • Sorting and filtering over tag name from gh response is still a thing as they respond with npm prefix which we don't want to use
  • Kept github api version in curl for future consistency

- Use jq to fully extract the name (+ sort)
- Inline function bodies
- Simplify comparison between old and new versions
@chrmod chrmod merged commit 7f13b8e into main May 22, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants