-
-
Notifications
You must be signed in to change notification settings - Fork 1
166 lines (139 loc) · 5.87 KB
/
pull-request.yml
File metadata and controls
166 lines (139 loc) · 5.87 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
161
162
163
164
165
166
name: Pull request
on:
pull_request:
types: [ opened, synchronize, reopened, closed ]
branches:
- 'main'
jobs:
ci:
name: CI
if: github.event.action != 'closed'
uses: ./.github/workflows/_build.yml
compute-version:
name: Compute version
runs-on: ubuntu-latest
if: |
contains(github.event.pull_request.labels.*.name, 'deploy') &&
(startsWith(github.head_ref, 'feature/') ||
startsWith(github.head_ref, 'fix/') ||
startsWith(github.head_ref, 'ci/'))
outputs:
canary_prefix: ${{ steps.generate_canary_version.outputs.canary_prefix }}
canary_version: ${{ steps.generate_canary_version.outputs.canary_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Generate Canary Version
id: generate_canary_version
run: |
BASE_VERSION=$(node -p "require('./package.json').version")
PR_NUMBER=${{ github.event.pull_request.number }}
COMMIT_HASH=${GITHUB_SHA::7}
CANARY_PREFIX="${BASE_VERSION}-canary.${PR_NUMBER}"
CANARY_VERSION="${CANARY_PREFIX}.${COMMIT_HASH}"
echo "CANARY_PREFIX=${CANARY_PREFIX}"
echo "CANARY_VERSION=${CANARY_VERSION}"
echo "CANARY_PREFIX=${CANARY_PREFIX}" >> $GITHUB_ENV
echo "CANARY_VERSION=${CANARY_VERSION}" >> $GITHUB_ENV
echo "canary_prefix=${CANARY_PREFIX}" >> $GITHUB_OUTPUT
echo "canary_version=${CANARY_VERSION}" >> $GITHUB_OUTPUT
publish-version:
name: Publish
runs-on: ubuntu-latest
needs: [ ci , compute-version ]
if: github.event.action != 'closed'
environment:
name: canary
url: https://www.npmjs.com/package/execution-engine/v/${{ needs.compute-version.outputs.canary_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: "https://registry.npmjs.org"
- name: Remove old Canary versions
id: unpublish_canary
uses: ./.github/actions/unpublish-prefix
with:
version_prefix: ${{ needs.compute-version.outputs.canary_prefix }}
confirm: 'I confirm to unpublish'
npm_token: ${{ secrets.NPM_TOKEN }}
- name: Install dependencies
run: npm ci
- name: Bump Version and Publish Canary
run: |
npm version ${{ needs.compute-version.outputs.canary_version }} --no-git-tag-version
npm publish --tag canary
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: prepare Cleanup Message
id: cleanup_message
shell: bash
run: |
if [[ -n "${{ steps.unpublish_canary.outputs.UNPUBLISHED_VERSIONS_BY_PREFIX }}" ]]; then
# Loop through each version and add a strikethrough (~) around each
RESULT_WITH_STRIKETHROUGH=""
for version in ${{ steps.unpublish_canary.outputs.UNPUBLISHED_VERSIONS_BY_PREFIX }}; do
RESULT_WITH_STRIKETHROUGH="~$version~ $RESULT_WITH_STRIKETHROUGH"
done
echo "cleanup_message=🚫 **Unpublished versions**: $RESULT_WITH_STRIKETHROUGH" >> "$GITHUB_ENV"
else
# If no unpublished versions, leave the message empty
echo "cleanup_message=🚫 **Unpublished versions**: ∅" >> "$GITHUB_ENV"
fi
- name: Comment on PR with deployed Version
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
${{ env.cleanup_message }}
✅ **Created Version:** `${{ needs.compute-version.outputs.canary_version }}`
📦 **Published on NPM:** [View on NPM](https://www.npmjs.com/package/execution-engine/v/${{ needs.compute-version.outputs.canary_version }})
> ⚠️ **Note:** This version is temporary and will be **unpublished** on the next PR update or merge.
reactions: 'rocket'
unpublish_version:
name: Unpublish
runs-on: ubuntu-latest
needs: compute-version
if: github.event.action == 'closed'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Remove old Canary versions
id: unpublish_canary_2
uses: ./.github/actions/unpublish-prefix
with:
version_prefix: ${{ needs.compute-version.outputs.canary_prefix }}
confirm: 'I confirm to unpublish'
npm_token: ${{ secrets.NPM_TOKEN }}
- name: prepare PR comment message for unpublish
id: cleanup_message
shell: bash
run: |
if [[ -n "${{ steps.unpublish_canary_2.outputs.UNPUBLISHED_VERSIONS_BY_PREFIX }}" ]]; then
# Loop through each version and add a strikethrough (~) around each
RESULT_WITH_STRIKETHROUGH=""
for version in ${{ steps.unpublish_canary_2.outputs.UNPUBLISHED_VERSIONS_BY_PREFIX }}; do
RESULT_WITH_STRIKETHROUGH="~$version~ $RESULT_WITH_STRIKETHROUGH"
done
echo "cleanup_message=🚫 **Unpublished versions**: $RESULT_WITH_STRIKETHROUGH" >> "$GITHUB_ENV"
else
# If no unpublished versions, leave the message empty
echo "cleanup_message=🚫 **Unpublished versions**: ∅" >> "$GITHUB_ENV"
fi
- name: Comment on PR with deployed Version
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
${{ env.cleanup_message }}
reactions: 'rocket'