forked from amplication/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (128 loc) · 4.4 KB
/
publish-on-comment.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
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
name: publish-on-comment
on:
issue_comment:
types: [created]
jobs:
check-comment:
name: Check comment for /publish
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }}
outputs:
trigger-comment: ${{ steps.check.outputs.triggered }}
steps:
- uses: khan/[email protected]
id: check
with:
trigger: "/publish"
prefix_only: "true"
reaction: "rocket"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
get-refs:
name: Resolve PR refs
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }}
outputs:
head: ${{ steps.head.outputs.result }}
base: ${{ steps.base.outputs.result }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get head
id: head
uses: actions/github-script@v5
with:
result-encoding: string
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
return pr.data.head.ref;
- name: Get base
id: base
uses: actions/github-script@v5
with:
result-encoding: string
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
return pr.data.base.ref;
get-affected-plugins:
name: Get affected plugins
needs: [check-comment, get-refs]
if: ${{ needs.check-comment.outputs.trigger-comment == 'true' }}
uses: ./.github/workflows/nx.template.yaml
with:
nx-head: ${{ needs.get-refs.outputs.head }}
nx-base: ${{ needs.get-refs.outputs.base }}
get-last-commit:
name: Get last commit short SHA of the PR
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }}
outputs:
last-commit-short-sha: ${{ steps.last-commit.outputs.result }}
steps:
- name: Get last commit SHA of the PR
id: last-commit
uses: actions/github-script@v5
with:
result-encoding: string
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
return pr.data.head.sha.substring(0, 7);
publish:
name: Publish beta version
runs-on: ubuntu-latest
needs: [get-affected-plugins, get-last-commit, get-refs]
if: ${{ needs.get-affected-plugins.outputs.affected-plugins != '[]' && needs.get-affected-plugins.outputs.affected-plugins != '' }}
strategy:
matrix:
affected-plugin: ${{ fromJson(needs.get-affected-plugins.outputs.affected-plugins) }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.get-refs.outputs.head }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
- name: Install dependencies and build 🔧
run: npm ci && npm run build
working-directory: plugins/${{ matrix.affected-plugin }}
- name: Publish version dry-run
run: npm publish --access public --tag beta --dry-run
working-directory: plugins/${{ matrix.affected-plugin }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish package on NPM [beta] 📦
run: |
VERSION=$(cat package.json | jq -r '.version')
npm version $VERSION-beta.pr-${{ github.event.issue.number }}.${{ needs.get-last-commit.outputs.last-commit-short-sha }}
npm publish --access public --tag beta
working-directory: plugins/${{ matrix.affected-plugin }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
create-comment:
name: Create comment
runs-on: ubuntu-latest
needs: [get-affected-plugins, publish]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create comment
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
body: |
Published beta version for ${{ needs.get-affected-plugins.outputs.affected-plugins }}