Skip to content

Commit

Permalink
allow bumping pkgx or pkgm formula (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl authored Jan 18, 2025
1 parent 591bbfc commit abcb700
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
22 changes: 13 additions & 9 deletions .github/actions/bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { backticks, run, panic } from "utils"
import { basename } from "deno/path/mod.ts"
import { crypto, toHashString } from "deno/crypto/mod.ts"

const formula = Deno.args[0];
const rootUrl = "https://github.com/pkgxdev/homebrew-made/releases/download"

const livecheck: LCResults[] = await (async () => {
if (Deno.args[0]) {
const [current, latest] = Deno.args
if (Deno.args[1]) {
const [current, latest] = Deno.args.slice(1)
return [{
formula: 'pkgx',
formula,
version: {
outdated: true,
current, latest
Expand Down Expand Up @@ -43,17 +44,20 @@ for (const pkg of livecheck) {
const name = basename(pkg.formula)
const formula = await Deno.readTextFile(`${name}.rb`)

const url = formula.match(/ url "(.*)"/)?.[1]
const url = formula.match(/ url "(.*)"/)?.[1]!
const newUrl = url.replaceAll(oldVersion, newVersion)
const newSha = await sha256(newUrl)

const bottles = await bottle(newVersion)
let newFormula = formula.replaceAll(url, newUrl).replace(/ sha256 ".+"/, ` sha256 "${newSha}"`)

// Generate new bottle block.
const newBottleBlock = generateBottleBlock(bottles, newVersion)
if (formula == 'pkgx') {
const bottles = await bottle(newVersion)

const newFormula = formula.replaceAll(url, newUrl).replace(/ sha256 ".+"/, ` sha256 "${newSha}"`)
.replace(/bottle do[\s\S]*?end$/m, newBottleBlock)
// Generate new bottle block.
const newBottleBlock = generateBottleBlock(bottles, newVersion)

newFormula = newFormula.replace(/bottle do[\s\S]*?end$/m, newBottleBlock)
}

await Deno.writeTextFile(`${name}.rb`, newFormula)

Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
version:
description: current version & new version space separated
required: false
formula:
default: pkgx
required: false

concurrency:
group: bump/${{ github.event.inputs.version || 'livecheck' }}
Expand All @@ -25,7 +28,7 @@ jobs:
- uses: Homebrew/actions/setup-homebrew@master
- uses: pkgxdev/setup@v2

- run: .github/actions/bump.ts ${{ github.event.inputs.version }}
- run: .github/actions/bump.ts ${{ github.event.inputs.formula }} ${{ github.event.inputs.version }}
id: bump
env:
TAP: pkgxdev/made
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/ci.bump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: ci/bumper

on:
pull_request:
paths:
- .github/actions/bump.ts
- .github/workflows/ci.bump.yml

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pkgxdev/setup@v3

- run: git checkout 591bbfc206850d6be45976fce9682d99c8179927 -- ./pkg[xm].rb
- run: .github/actions/bump.ts pkgx 2.1.1 2.1.2
- run: .github/actions/bump.ts pkgm 0.3.0 0.3.1

- uses: actions/upload-artifact@v4
with:
path: '*.rb'
name: formulae

- uses: Homebrew/actions/setup-homebrew@master
- run: brew install ./pkgm.rb

0 comments on commit abcb700

Please sign in to comment.