Publish PR Packages #5270
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v6 | |
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> |