|
name: Publish release on push tag |
|
|
|
on: |
|
push: |
|
tags: ['v*'] |
|
|
|
jobs: |
|
build-and-draft: |
|
permissions: |
|
contents: write |
|
runs-on: ubuntu-latest |
|
|
|
steps: |
|
- uses: actions/checkout@v6 |
|
- name: Use Node.js 20 |
|
uses: actions/setup-node@v6 |
|
with: |
|
node-version: 20 |
|
cache: 'npm' |
|
- id: get-version |
|
name: Get version |
|
run: echo version=`cat package.json | jq -r '.version'` >> $GITHUB_OUTPUT |
|
- name: Validate version |
|
if: ${{ contains(steps.get-version.outputs.version, '-') }} |
|
run: | |
|
echo Version number must not be a prerelease. |
|
exit 1 |
|
- run: npm clean-install |
|
- run: npm run prepublishOnly |
|
- name: Upload tarball artifact |
|
uses: actions/upload-artifact@v6 |
|
with: |
|
name: bundle |
|
path: ./dist |
|
- run: npm pack |
|
- name: Upload tarball artifact |
|
uses: actions/upload-artifact@v6 |
|
with: |
|
name: tarball |
|
path: ./*.tgz |
|
- name: Draft a new release |
|
run: gh release create ${{ github.ref_name }} ./dist/directline.js ./*.tgz --draft --notes-file ./CHANGELOG.md |
|
env: |
|
GH_TOKEN: ${{ github.token }} |
|
|
|
publish-package: |
|
environment: |
|
name: npm |
|
url: https://npmjs.com/package/${{ steps.get-version.outputs.package-name }}/v/${{ steps.get-version.outputs.version }} |
|
needs: build-and-draft |
|
runs-on: ubuntu-latest |
|
permissions: |
|
contents: read |
|
id-token: write |
|
|
|
steps: |
|
- uses: actions/setup-node@v6 |
|
with: |
|
node-version: 24 # Newer Node.js version for OIDC publishing |
|
registry-url: https://registry.npmjs.org/ |
|
- name: Download tarball artifact |
|
uses: actions/download-artifact@v7 |
|
with: |
|
name: tarball |
|
- id: get-version |
|
name: Get version |
|
run: | |
|
echo package-name=`tar --extract --file=\`ls ./*.tgz\` --to-stdout package/package.json | jq -r .name` >> $GITHUB_OUTPUT |
|
echo version=`tar --extract --file=\`ls ./*.tgz\` --to-stdout package/package.json | jq -r .version` >> $GITHUB_OUTPUT |
|
- run: npm publish --access public `ls ./*.tgz` |
|
- name: Generate job summary |
|
run: echo "NPM package has been published to https://npmjs.com/package/${{ steps.get-version.outputs.package-name }}/v/${{ steps.get-version.outputs.version }}." > $GITHUB_STEP_SUMMARY |
|
|
|
publish-release: |
|
needs: |
|
- build-and-draft |
|
- publish-package |
|
permissions: |
|
contents: write |
|
runs-on: ubuntu-latest |
|
|
|
steps: |
|
- name: Publish release |
|
run: gh release edit ${{ github.ref_name }} --draft=false --repo ${{ github.repository }} |
|
env: |
|
GH_TOKEN: ${{ github.token }} |
|
- name: Generate job summary |
|
run: echo "GitHub release created at https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}." >> $GITHUB_STEP_SUMMARY |