-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ci): auto sync with upstream #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
chrmod
left a comment
There was a problem hiding this 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
|
We'll need to:
|
.github/workflows/sync.yml
Outdated
| 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 | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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 |
There was a problem hiding this comment.
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
npmprefix 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
Unattended pull creation by checking regularly.