Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ This directory contains the GitHub Actions workflows for the adblock-compiler pr

## Workflows

### Auto Version Bump (`version-bump.yml`)

Automatically bumps the version number when a pull request is opened.

#### Trigger
- Runs when a pull request is opened targeting master/main branches
- Does not run for PRs created by bots (github-actions[bot], dependabot[bot])

#### What it does
1. Extracts the current version from `deno.json`
2. Increments the patch version (e.g., 0.6.88 → 0.6.89)
3. Updates the version in both `deno.json` and `package.json`
4. Commits the changes with message: `chore: bump version to X.Y.Z`
5. Pushes the commit to the PR branch
6. Adds a comment to the PR confirming the version bump

#### Why it's needed
JSR (JavaScript Registry) only accepts new versions when publishing. Without automatic version bumping, merged PRs would not trigger a new JSR publication, preventing updated code from being available to users.

#### Permissions
- `contents: write` - Required to commit and push version changes
- `pull-requests: write` - Required to add comments to PRs

### CI/CD Pipeline (`ci.yml`)

The main CI/CD pipeline that runs on every push and pull request to master/main branches.
Expand Down
136 changes: 136 additions & 0 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: Auto Version Bump

on:
pull_request:
types: [opened]
branches: [master, main]

permissions:
contents: write
pull-requests: write

jobs:
bump-version:
name: Bump Version Number
runs-on: ubuntu-latest
# Only run on PRs not created by bots
if: github.actor != 'github-actions[bot]' && github.actor != 'dependabot[bot]'
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v2.4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Bump version in deno.json
id: bump_version
run: |
# Read current version from deno.json using deno for robust JSON parsing
if [ ! -f "deno.json" ]; then
echo "Error: deno.json not found"
exit 1
fi

CURRENT_VERSION=$(deno eval 'console.log(JSON.parse(Deno.readTextFileSync("deno.json")).version)' 2>&1) || {
echo "Error: Failed to read version from deno.json"
exit 1
}
echo "Current version: $CURRENT_VERSION"

# Validate version format (must be major.minor.patch with numeric parts only)
if ! [[ "$CURRENT_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version '$CURRENT_VERSION' is not in valid semver format (major.minor.patch)"
exit 1
fi

# Split version into parts
IFS='.' read -r -a version_parts <<< "$CURRENT_VERSION"
MAJOR="${version_parts[0]}"
MINOR="${version_parts[1]}"
PATCH="${version_parts[2]}"

# Validate PATCH is numeric (extra safety check)
if ! [[ "$PATCH" =~ ^[0-9]+$ ]]; then
echo "Error: Patch version '$PATCH' is not numeric"
exit 1
fi

# Bump patch version
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
echo "New version: $NEW_VERSION"

# Update deno.json using deno for safe JSON manipulation
# Pass version as command-line argument to avoid shell injection
deno eval "
const newVersion = Deno.args[0];
const config = JSON.parse(Deno.readTextFileSync('deno.json'));
config.version = newVersion;
Deno.writeTextFileSync('deno.json', JSON.stringify(config, null, 4) + '\n');
" "$NEW_VERSION"

# Output for later steps
echo "old_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT

- name: Bump version in package.json
run: |
# Update package.json if it exists with a version field
if [ -f "package.json" ] && grep -q '"version"' package.json; then
NEW_VERSION="${{ steps.bump_version.outputs.new_version }}"
# Use deno for safe JSON manipulation
# Pass version as command-line argument to avoid shell injection
deno eval "
const newVersion = Deno.args[0];
const pkg = JSON.parse(Deno.readTextFileSync('package.json'));
pkg.version = newVersion;
Deno.writeTextFileSync('package.json', JSON.stringify(pkg, null, '\t') + '\n');
" "$NEW_VERSION"
echo "Updated package.json version to ${NEW_VERSION}"
fi

- name: Check for changes
id: check_changes
run: |
if git diff --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No version changes needed"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Version files updated"
fi

- name: Commit and push version bump
if: steps.check_changes.outputs.has_changes == 'true'
run: |
git add deno.json package.json
git commit -m "chore: bump version to ${{ steps.bump_version.outputs.new_version }}"
git push origin ${{ github.head_ref }}

- name: Add comment to PR
if: steps.check_changes.outputs.has_changes == 'true'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: '🚀 Version automatically bumped from `${{ steps.bump_version.outputs.old_version }}` to `${{ steps.bump_version.outputs.new_version }}`'
})
4 changes: 1 addition & 3 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.