Chore/publish as package #85
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Publish [ALPHA] | |
on: | |
issue_comment: | |
types: [ created ] | |
pull_request: | |
types: [ opened, synchronize ] | |
jobs: | |
publish-alpha: | |
if: | | |
(github.event_name == 'issue_comment' && | |
github.event.issue.pull_request && | |
contains(github.event.comment.body, 'build')) || | |
github.event_name == 'pull_request' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: ./.github/actions/setup-node-pnpm | |
name: Setup Node and pnpm | |
- name: Build | |
run: pnpm build | |
- name: Create new version | |
run: | | |
# Get lastest version from package.json | |
CURRENT_VERSION=$(node -p "require('./package.json').version") | |
PR_NUMBER=${{ github.event.pull_request.number }} | |
COMMIT_SHA=$(git rev-parse --short ${{ github.sha }}) | |
# Create alpha version | |
ALPHA_VERSION="${CURRENT_VERSION}-alpha.pr-${PR_NUMBER}-$(date +%Y%m%d%H%M%S)-${COMMIT_SHA}" | |
# Update package.json version | |
pnpm version $ALPHA_VERSION --no-git-tag-version | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish to registry | |
run: | | |
# Publish alpha version | |
pnpm publish --tag alpha --no-git-checks | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Keep only latest 3 alpha versions for this PR | |
uses: ./.github/actions/cleanup-alpha-versions | |
with: | |
token: ${{ github.token }} | |
pr-number: ${{ github.event.pull_request.number }} | |
keep-latest: 3 | |
- name: Remove old alpha versions of any PR | |
uses: ./.github/actions/cleanup-alpha-versions | |
with: | |
token: ${{ github.token }} | |
days: 5 | |