-
Notifications
You must be signed in to change notification settings - Fork 242
108 lines (89 loc) · 3.96 KB
/
handler.publish-pr-packages.yml
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
name: Publish PR Packages
on:
workflow_run:
workflows: ["CD | Create PR Artifact"]
types:
- completed
jobs:
publish_pr_packages:
name: NPM publish PR to Github
permissions: write-all
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
- name: Show context
env:
HEAD_REF: ${{ github.head_ref }}
GITHUB_REF: ${{ github.ref }}
run: |
echo github.event_name: ${{ github.event_name }}
echo github.sha: ${{ github.sha }}
echo github.repository: ${{ github.repository }}
echo github.ref: "$GITHUB_REF"
echo github.head_ref: "$HEAD_REF"
echo github.base_ref: ${{ github.base_ref }}
- name: Download artifact
continue-on-error: true
id: download_artifact
uses: dawidd6/action-download-artifact@v4
with:
workflow: ${{ github.event.workflow_run.workflow_id }}
workflow_conclusion: success
if_no_artifact_found: fail
- name: Get PR data
if: steps.download_artifact.outcome == 'success'
id: pr
run: |
ls -R pr-packages
pr_number=$(ls pr-packages)
# find num of files and print a dot for each file and count the dots
n_packages=$(find "pr-packages/$pr_number" -maxdepth 1 -type f -printf '.' | wc -c)
echo pr_number: "$pr_number"
echo n_packages: "$n_packages"
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
echo "n_packages=$n_packages" >> "$GITHUB_OUTPUT"
- name: Publish to github
if: steps.download_artifact.outcome == 'success'
run: |
pr_number="${{ steps.pr.outputs.pr_number }}"
tasks/npmrc-use-github.sh > pr-packages/$pr_number/.npmrc # using GITHUB_TOKEN
cd pr-packages/$pr_number
shopt -s nullglob
for p in * ; do
npm --userconfig .npmrc publish --access public --tag "PR$pr_number" "$p"
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Find Comment
uses: peter-evans/find-comment@v1
if: ${{ steps.pr.outputs.n_packages > 0 && steps.download_artifact.outcome == 'success' }}
id: fc
with:
issue-number: ${{ steps.pr.outputs.pr_number }}
comment-author: "github-actions[bot]"
- name: Create comment
if: ${{ steps.pr.outputs.n_packages > 0 && steps.fc.outputs.comment-id == 0 && steps.download_artifact.outcome == 'success'}}
uses: peter-evans/create-or-update-comment@v2
with:
issue-number: ${{ steps.pr.outputs.pr_number }}
body: |
### 📦 PR Packages
Install this PR (you need to setup Github packages):
```bash
yarn add @superfluid-finance/ethereum-contracts@PR${{ steps.pr.outputs.pr_number }}
yarn add @superfluid-finance/sdk-core@PR${{ steps.pr.outputs.pr_number }}
yarn add @superfluid-finance/sdk-redux@PR${{ steps.pr.outputs.pr_number }}
```
<details><summary>:octocat: Click to learn how to use Github packages</summary>
To use the Github package registry, create a token with "read:packages" permission. See [Creating a personal access token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) for help.
Next add these lines to your `.npmrc` file, replacing TOKEN with your personal access token. See [Installing a package from Github](https://docs.github.com/en/packages/guides/configuring-npm-for-use-with-github-packages#installing-a-package) if you get stuck.
```
@superfluid-finance:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=TOKEN
```
</details>