2021-04-06 17:37:17 +00:00
name : Publish NPM
on :
workflow_dispatch :
inputs :
package :
required : true
2022-05-03 15:10:13 +00:00
description : 'core, artifact, cache, exec, github, glob, http-client, io, tool-cache'
2021-04-06 17:37:17 +00:00
jobs :
test :
2023-03-07 10:41:27 +00:00
outputs :
sha : ${{ steps.commit.outputs.sha }}
tag : ${{ steps.tag.outputs.tag }}
2021-04-06 17:37:17 +00:00
runs-on : macos-latest
steps :
- name : setup repo
2023-01-03 15:59:01 +00:00
uses : actions/checkout@v3
2023-03-07 10:41:27 +00:00
- id : commit
run : echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- id : tag
2023-03-07 11:11:44 +00:00
run : echo "tag=@actions/${{ github.event.inputs.package }}@$(cat packages/${{ github.event.inputs.package }}/package.json | jq -r .version" >> "$GITHUB_OUTPUT"
2021-04-06 17:37:17 +00:00
- name : verify package exists
run : ls packages/${{ github.event.inputs.package }}
2022-05-03 15:10:13 +00:00
2022-12-14 00:19:05 +00:00
- name : Set Node.js 16.x
2023-01-03 15:38:50 +00:00
uses : actions/setup-node@v3
2021-12-07 15:38:25 +00:00
with :
2022-12-14 00:19:05 +00:00
node-version : 16. x
2022-05-03 15:10:13 +00:00
2021-04-06 17:37:17 +00:00
- name : npm install
run : npm install
2022-05-03 15:10:13 +00:00
2021-04-06 17:37:17 +00:00
- name : bootstrap
run : npm run bootstrap
2022-05-03 15:10:13 +00:00
2021-04-06 17:37:17 +00:00
- name : build
run : npm run build
2022-05-03 15:10:13 +00:00
2021-04-06 17:37:17 +00:00
- name : test
run : npm run test
- name : pack
run : npm pack
working-directory : packages/${{ github.event.inputs.package }}
2022-05-03 15:10:13 +00:00
2021-04-06 17:37:17 +00:00
- name : upload artifact
2023-01-03 15:59:01 +00:00
uses : actions/upload-artifact@v3
2021-04-06 17:37:17 +00:00
with :
name : ${{ github.event.inputs.package }}
path : packages/${{ github.event.inputs.package }}/*.tgz
2022-05-03 15:10:13 +00:00
2021-04-06 17:37:17 +00:00
publish :
runs-on : macos-latest
needs : test
environment : npm-publish
steps :
2022-05-03 15:10:13 +00:00
2021-04-06 17:37:17 +00:00
- name : download artifact
2023-01-03 15:59:01 +00:00
uses : actions/download-artifact@v3
2021-04-06 17:37:17 +00:00
with :
name : ${{ github.event.inputs.package }}
2021-04-06 18:41:33 +00:00
- name : setup authentication
run : echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
2022-05-03 15:10:13 +00:00
env :
2021-04-06 17:37:17 +00:00
NPM_TOKEN : ${{ secrets.TOKEN }}
2021-04-06 18:41:33 +00:00
- name : publish
run : npm publish *.tgz
2021-04-06 17:37:17 +00:00
- name : notify slack on failure
if : failure()
run : |
curl -X POST -H 'Content-type : application/json' --data '{"text":":pb__failed: Failed to publish a new version of ${{ github.event.inputs.package }}"}' $SLACK_WEBHOOK
2022-05-03 15:10:13 +00:00
env :
2021-04-06 17:37:17 +00:00
SLACK_WEBHOOK : ${{ secrets.SLACK }}
2022-05-03 15:10:13 +00:00
2021-04-06 17:37:17 +00:00
- name : notify slack on success
if : success()
run : |
curl -X POST -H 'Content-type : application/json' --data '{"text":":dance: Successfully published a new version of ${{ github.event.inputs.package }}"}' $SLACK_WEBHOOK
2022-05-03 15:10:13 +00:00
env :
2021-04-06 17:37:17 +00:00
SLACK_WEBHOOK : ${{ secrets.SLACK }}
2023-03-07 10:41:27 +00:00
tag :
2023-03-07 11:05:52 +00:00
name : "Tag ${{ needs.test.outputs.sha }} with ${{ needs.test.outputs.tag }}"
2023-03-07 10:41:27 +00:00
runs-on : "macos-latest"
needs : [ test, publish]
steps :
- uses : actions/checkout@v3
- name : Create tag
uses : actions/github-script@v6
with :
2023-03-07 10:51:42 +00:00
script : |
github.rest.git.createRef({
owner : context.repo.owner,
repo : context.repo.repo,
ref : 'refs/tags/${{ needs.test.outputs.tag }}' ,
sha : '${{ needs.test.outputs.sha }}'
})
2023-03-07 10:41:27 +00:00
- name : notify slack on failure
2023-03-07 10:44:40 +00:00
if : failure()
run : |
curl -X POST -H 'Content-type : application/json' --data '{"text":":pb__failed: Publish of ${{ github.event.inputs.package }} was successful, but failed to tag commit ${{ needs.test.outputs.sha }} with version ${{ needs.test.outputs.tag }}"}' $SLACK_WEBHOOK
env :
SLACK_WEBHOOK : ${{ secrets.SLACK }}
2022-05-03 15:10:13 +00:00