mirror of https://github.com/actions/toolkit
109 lines
3.2 KiB
YAML
109 lines
3.2 KiB
YAML
name: Publish NPM
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
package:
|
|
required: true
|
|
description: 'core, artifact, cache, exec, github, glob, http-client, io, tool-cache'
|
|
|
|
jobs:
|
|
test:
|
|
outputs:
|
|
sha: ${{ steps.commit.outputs.sha }}
|
|
tag: ${{ steps.tag.outputs.tag }}
|
|
runs-on: macos-latest
|
|
steps:
|
|
- name: setup repo
|
|
uses: actions/checkout@v3
|
|
- id: commit
|
|
run: echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
|
|
- id: tag
|
|
run: echo "tag=${{ github.event.inputs.package }}-$(cat packages/tool-cache/package.json | jq .version)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: verify package exists
|
|
run: ls packages/${{ github.event.inputs.package }}
|
|
|
|
- name: Set Node.js 16.x
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 16.x
|
|
|
|
- name: npm install
|
|
run: npm install
|
|
|
|
- name: bootstrap
|
|
run: npm run bootstrap
|
|
|
|
- name: build
|
|
run: npm run build
|
|
|
|
- name: test
|
|
run: npm run test
|
|
|
|
- name: pack
|
|
run: npm pack
|
|
working-directory: packages/${{ github.event.inputs.package }}
|
|
|
|
- name: upload artifact
|
|
uses: actions/upload-artifact@v3
|
|
with:
|
|
name: ${{ github.event.inputs.package }}
|
|
path: packages/${{ github.event.inputs.package }}/*.tgz
|
|
|
|
publish:
|
|
runs-on: macos-latest
|
|
needs: test
|
|
environment: npm-publish
|
|
steps:
|
|
|
|
- name: download artifact
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: ${{ github.event.inputs.package }}
|
|
|
|
- name: setup authentication
|
|
run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
|
|
env:
|
|
NPM_TOKEN: ${{ secrets.TOKEN }}
|
|
|
|
- name: publish
|
|
run: npm publish *.tgz
|
|
|
|
- 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
|
|
env:
|
|
SLACK_WEBHOOK: ${{ secrets.SLACK }}
|
|
|
|
- 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
|
|
env:
|
|
SLACK_WEBHOOK: ${{ secrets.SLACK }}
|
|
tag:
|
|
name: "Tag commit with ${{ github.event.inputs.package }}-version"
|
|
runs-on: "macos-latest"
|
|
needs: [test, publish]
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
- name: Create tag
|
|
uses: actions/github-script@v6
|
|
with:
|
|
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 }}'
|
|
})
|
|
- name: notify slack on failure
|
|
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 }}
|
|
|