Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add Actions config to publish to Packages #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/publish-on-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Publish Package to GitHub

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16
- run: yarn install --immutable --immutable-cache --check-cache
- run: yarn build:library
# TODO: tests
# - run: yarn test

# Reference https://github.com/aaronpowell/react-foldable/blob/main/.github/workflows/build.yml
# https://www.aaron-powell.com/posts/2020-11-06-deploy-to-github-packages-with-github-actions/
package:
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v2
with:
node-version: 16

- run: yarn install --immutable --immutable-cache --check-cache
- run: yarn build:library
# - run: npm version prerelease --preid=ci-$GITHUB_RUN_ID --no-git-tag-version
- run: yarn pack
- name: Upload package
uses: actions/upload-artifact@v2
with:
name: package
path: "*.tgz"
if-no-files-found: error

# Reference https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#example-workflow
publish:
name: "Publish to GitHub Packages"
needs: [package]
runs-on: ubuntu-latest
# if: ${{ github.repository_owner == 'OWNER' }} # && github.token != ''
steps:
- uses: actions/checkout@v2
- name: Download package
uses: actions/download-artifact@v2
with:
name: package
- uses: actions/setup-node@v2
with:
node-version: '16.x'
registry-url: https://npm.pkg.github.com/
- run: npm publish $(ls *.tgz) # using yarn fails to authenticate
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}