-
Notifications
You must be signed in to change notification settings - Fork 52
160 lines (152 loc) · 5.6 KB
/
Copy pathgh-alpha-release.yml
File metadata and controls
160 lines (152 loc) · 5.6 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Alpha Release
on:
workflow_dispatch:
inputs:
pr_number:
description: "PR number (for manual runs)"
required: true
pull_request:
branches:
- master
jobs:
resolve-alpha:
runs-on: ubuntu-latest
outputs:
alpha_version: ${{ steps.set_alpha_version.outputs.alpha_version }}
pr_number: ${{ steps.set_alpha_version.outputs.pr_number }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref }}
- name: Resolve alpha version
id: set_alpha_version
env:
EVENT_NAME: ${{ github.event_name }}
HEAD_REF: ${{ github.head_ref }}
PR_NUM: ${{ github.event.pull_request.number }}
INPUT_PR_NUMBER: ${{ github.event.inputs.pr_number }}
run: |
BASE_VERSION=$(node -p 'require("./lerna.json").version')
SHORT_SHA=$(git rev-parse --short HEAD)
ALPHA_VERSION=""
PR_NUMBER=""
if [ "$EVENT_NAME" = "pull_request" ]; then
BRANCH="$HEAD_REF"
if [[ "$BRANCH" == alpha/* ]]; then
message=$(git log -1 --pretty=%B | head -n 1)
if [[ "$message" != *'[skip alpha]'* ]]; then
PR_NUMBER="$PR_NUM"
ALPHA_VERSION="${BASE_VERSION}-alpha.p${PR_NUMBER}.${SHORT_SHA}"
fi
fi
elif [ "$EVENT_NAME" = "workflow_dispatch" ]; then
PR_NUMBER="$INPUT_PR_NUMBER"
if [ -n "$PR_NUMBER" ]; then
ALPHA_VERSION="${BASE_VERSION}-alpha.p${PR_NUMBER}.${SHORT_SHA}"
fi
fi
echo "alpha_version=$ALPHA_VERSION" >> $GITHUB_OUTPUT
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "ALPHA_VERSION=$ALPHA_VERSION"
echo "PR_NUMBER=$PR_NUMBER"
tests:
if: needs.resolve-alpha.outputs.alpha_version != ''
needs: resolve-alpha
uses: ./.github/workflows/version-tests.yml
all-tests-pass:
if: needs.resolve-alpha.outputs.alpha_version != ''
runs-on: ubuntu-latest
needs: [tests, resolve-alpha]
steps:
- run: echo "All tests completed"
publish-alpha:
if: needs.resolve-alpha.outputs.alpha_version != ''
runs-on: ubuntu-latest
needs: [all-tests-pass, resolve-alpha]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: pnpm install
- name: Version all packages
env:
ALPHA_VERSION: ${{ needs.resolve-alpha.outputs.alpha_version }}
run: pnpm version-all "$ALPHA_VERSION" -y
- name: Git status
run: git status
- name: Commit version changes
env:
ALPHA_VERSION: ${{ needs.resolve-alpha.outputs.alpha_version }}
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add -A
git commit -m "chore: version bump to $ALPHA_VERSION [skip ci]" --no-verify || echo "No changes to commit"
- name: Git status after
run: git status
- name: Build packages
run: pnpm build
- name: Validate NPM Token
run: |
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
npm whoami
rm -f .npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Publish Alpha
run: npm run publish -- --dist-tag alpha
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Add comment to PR
uses: actions/github-script@v4
continue-on-error: true
env:
PR_NUMBER: ${{ needs.resolve-alpha.outputs.pr_number }}
ALPHA_VERSION: ${{ needs.resolve-alpha.outputs.alpha_version }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prNumber = process.env.PR_NUMBER || (context.issue && context.issue.number);
const alphaVersion = process.env.ALPHA_VERSION;
if (!prNumber) {
core.warning('No PR number available to comment on.');
return;
}
const comments = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const botComment = comments.data.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('Alpha versions of packages are published')
);
const commentBody = `Alpha versions of packages are published 📦\n\n` +
`PR: #${prNumber}\n` +
`Version: ${alphaVersion}\n` +
`NPM: https://www.npmjs.com/package/@streamflow/common/v/${alphaVersion}`;
if (botComment) {
await github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody
});
}