name: Publish
on:
workflow_run:
workflows: ["Release"]
types: [completed]
permissions:
contents: write
jobs:
resolve-tag:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-22.04
outputs:
tag: ${{ steps.tag.outputs.tag }}
prerelease: ${{ steps.tag.outputs.prerelease }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Get tag at commit
id: tag
run: |
SHA="${{ github.event.workflow_run.head_sha }}"
TAG=$(git tag --points-at "$SHA" | head -1)
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
# prerelease if tag contains a hyphen (e.g. v0.10.0-rc.1)
if [[ "$TAG" == *"-"* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
install-scripts:
needs: resolve-tag
if: ${{ needs.resolve-tag.outputs.tag != '' }}
runs-on: ubuntu-22.04
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.resolve-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Upload install scripts
run: |
gh release upload "${TAG}" scripts/install.sh scripts/install.ps1 --clobber
publish-homebrew:
needs: resolve-tag
if: ${{ needs.resolve-tag.outputs.tag != '' && needs.resolve-tag.outputs.prerelease == 'false' }}
runs-on: ubuntu-22.04
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USER: "zv bot"
GITHUB_EMAIL: "bot@zv.dev"
TAG: ${{ needs.resolve-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
repository: "weezy20/homebrew-tap"
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Generate formula
run: |
curl -fsSL "https://raw.githubusercontent.com/weezy20/zv/${TAG}/scripts/generate-formula.sh" -o generate-formula.sh
chmod +x generate-formula.sh
bash generate-formula.sh "${TAG}" > Formula/zv.rb
- name: Commit formula
run: |
VERSION="${TAG#v}"
git config --global user.name "${GITHUB_USER}"
git config --global user.email "${GITHUB_EMAIL}"
export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
brew update
brew style --except-cops FormulaAudit/Homepage,FormulaAudit/Desc,FormulaAuditStrict --fix "Formula/zv.rb" || true
git add "Formula/zv.rb"
git commit -m "zv ${VERSION}"
git push
publish-npm:
needs: resolve-tag
if: ${{ needs.resolve-tag.outputs.tag != '' && needs.resolve-tag.outputs.prerelease == 'false' }}
runs-on: ubuntu-22.04
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.resolve-tag.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Prepare npm package
env:
ZV_VERSION: ${{ needs.resolve-tag.outputs.tag }}
run: |
cd npm
bash prepack.sh
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Publish
run: |
cd npm
npm publish --access public --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}