From da409cd804cd7aba04c9d9775dac72e289fc496f Mon Sep 17 00:00:00 2001 From: Dotan Nahum Date: Mon, 28 Feb 2022 15:50:15 +0200 Subject: [PATCH] move to action homebrew --- .github/workflows/cd.yml | 14 +++++++++++++- scripts/standalone.js | 42 +++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index ad3f9e68..c5308c92 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -29,8 +29,20 @@ jobs: - run: npm publish # add the package to npm env: NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} - - run: yarn standalone # creates binaries + updates homebrew + - run: yarn standalone # creates binaries - name: Github Release # adds the binaries to github release uses: softprops/action-gh-release@v1 with: files: "standalone/*" + - name: Extract version + id: extract-version + run: | + printf "::set-output name=%s::%s\n" tag-name "${GITHUB_REF#refs/tags/}" + - uses: mislav/bump-homebrew-formula-action@v1 + with: + formula-path: hygen.rb + homebrew-tap: jondot/homebrew-tap + download-url: "https://github.com/hygen/releases/download/${{ steps.extract-version.outputs.tag-name }}/hygen.macos.${{ steps.extract-version.outputs.tag-name }}.tar.gz" + commit-message: updating formula for Hygen + env: + COMMITTER_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/standalone.js b/scripts/standalone.js index b0eba1d9..eacaf2e6 100644 --- a/scripts/standalone.js +++ b/scripts/standalone.js @@ -39,27 +39,29 @@ const main = async () => { console.log('standalone: done.') console.log((await execa.command(`ls ${wd}`, opts)).stdout) - console.log('standalone: publishing to homebrew tap...') - const matches = ( - await execa.command(`shasum -a 256 ${wd}/hygen.macos.v${v}.tar.gz`, opts) - ).stdout.match(/([a-f0-9]+)\s+/) - if (matches && matches.length > 1) { - const sha = matches[1] - await fs.writeFile('/tmp/hygen.rb', brewFormula(sha, v)) // eslint-disable-line @typescript-eslint/no-use-before-define - const cmd = [ - `cd /tmp`, - `git clone git://${repo} brew-tap`, - `cd brew-tap`, - `mv /tmp/hygen.rb .`, - `git config user.email jondotan@gmail.com`, - `git config user.name 'Dotan Nahum'`, - `git add .`, - `git commit -m 'hygen: auto-release'`, - `git push https://${process.env.GITHUB_TOKEN}@${repo}`, - ].join(' && ') - await execa.command(cmd, opts) + if (process.env.MANUAL_HB_PUBLISH) { + console.log('standalone: publishing to homebrew tap...') + const matches = ( + await execa.command(`shasum -a 256 ${wd}/hygen.macos.v${v}.tar.gz`, opts) + ).stdout.match(/([a-f0-9]+)\s+/) + if (matches && matches.length > 1) { + const sha = matches[1] + await fs.writeFile('/tmp/hygen.rb', brewFormula(sha, v)) // eslint-disable-line @typescript-eslint/no-use-before-define + const cmd = [ + `cd /tmp`, + `git clone git://${repo} brew-tap`, + `cd brew-tap`, + `mv /tmp/hygen.rb .`, + `git config user.email jondotan@gmail.com`, + `git config user.name 'Dotan Nahum'`, + `git add .`, + `git commit -m 'hygen: auto-release'`, + `git push https://${process.env.GITHUB_TOKEN}@${repo}`, + ].join(' && ') + await execa.command(cmd, opts) - console.log('standalone: publish done.') + console.log('standalone: publish done.') + } } }