Last active
June 17, 2020 16:16
-
-
Save easa/4b92078f14e4d2dd1470743afef64734 to your computer and use it in GitHub Desktop.
npm publish to gpr
This file contains hidden or 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
# on a situation that both publish on npm and gpr are required. the package.json file should stay clean! | |
# but other ways to set the registry won't work so there we should change the package.json on bash! | |
# there we go: | |
jobs: | |
publish-gpr: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v1 | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: 12 | |
- name: Set Registry to Package.json | |
# the actual copy the registry into the package.json! change the username to the user's or org's username! | |
run: | | |
# remove one last charachter of the file (the '}') here... don't left any space or other character at end of package.json instead of the '}' | |
truncate -s-1 ./package.json | |
# the copy of registry | |
echo ",\"publishConfig\":{\"registry\":\"https://npm.pkg.github.com/@username\"}}" >> ./package.json | |
# show the file (unnecessary) | |
cat "./package.json" | |
- name: Test & Build | |
run: | | |
npm ci | |
npm test | |
npm run build | |
- name: Copy Static Files to ./dist/ | |
# this is for copy all other file than builds to the pakcage folder | |
run: cp -r ./package.json ./dist/ && cp -r ./LICENSE ./dist/ && cp -r ./README.md ./dist/ | |
- name: Set GPR Configs | |
run: | | |
npm config set //npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }} | |
npm config list # to show the configs! | |
- name: Publish GPR | |
run: cd dist && npm publish # publish the ./dist folder | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} |
This file contains hidden or 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
{ | |
"all other stuff" : "when using the package registery config (just this option is working right now! #bug) there's no need to the complicated-publish-bash.yml file!", | |
"publishConfig": { | |
"registry":"https://npm.pkg.github.com/@username" | |
} | |
} |
This file contains hidden or 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 Github Package | |
on: [push] | |
jobs: | |
publish-gpr: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v1 | |
with: | |
node-version: 12 | |
- name: Publish to GitHub Package Registry | |
run: | | |
# so simple and have only two steps: | |
# set the publish registry config of npm | |
npm config set //npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }} | |
# the publish command | |
npm publish |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment