-
Notifications
You must be signed in to change notification settings - Fork 1
68 lines (55 loc) · 1.91 KB
/
build-and-publish-alpha.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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