Publish to NPM #71
This file contains 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 to NPM | |
on: | |
workflow_dispatch: | |
inputs: | |
job: | |
description: Package to publish | |
required: true | |
type: choice | |
options: | |
- cli | |
- shared | |
default: cli | |
semver: | |
description: Bump version | |
required: true | |
type: choice | |
options: | |
- patch | |
- minor | |
- major | |
default: patch | |
build-docker: | |
description: Release companion Docker image | |
type: boolean | |
default: true | |
jobs: | |
deploy-cli: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{steps.version-out.outputs.version}} | |
env: | |
DIR: apps/${{github.event.inputs.job}} | |
steps: | |
- uses: actions/checkout@v4.1.5 | |
with: | |
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}' | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install deps | |
run: npm i --workspaces | |
- name: Compile | |
run: npm run build --workspaces | |
- name: Run test | |
run: npm run test --workspaces | |
- name: Bump version | |
run: cd ${{env.DIR}} && npm version ${{github.event.inputs.semver}} | |
- name: NPM Publish | |
id: publish | |
uses: JS-DevTools/npm-publish@v3.1.1 | |
with: | |
token: ${{ secrets.NPM_TOKEN }} | |
package: ${{env.DIR}} | |
ignore-scripts: false | |
- name: Export version to Docker jobs | |
id: version-out | |
run: echo "version=${{steps.publish.outputs.version}}" >> $GITHUB_OUTPUT | |
- name: Commit package.json changes | |
uses: EndBug/add-and-commit@v9.1.4 | |
with: | |
author_name: Sokari | |
author_email: sokariharry@gmail.com | |
message: "Release ${{github.event.inputs.job}} package version ${{ steps.publish.outputs.version }}" | |
add: '${{ env.DIR }}/*.json' | |
push: 'origin main --force' | |
tag: 'v${{steps.publish.outputs.version}}-${{github.event.inputs.job}} --force' | |
deploy-docker: | |
if: ${{ github.event.inputs.job == 'cli' && github.event.inputs.build-docker == 'true' }} | |
runs-on: ubuntu-latest | |
needs: deploy-cli | |
env: | |
DIR: apps/docker | |
steps: | |
- uses: actions/checkout@v4.1.5 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: arm64,amd64 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Docker login | |
uses: docker/#-action@v3 | |
with: | |
username: ${{ vars.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v6.10.0 | |
with: | |
context: ${{env.DIR}} | |
file: ${{env.DIR}}/Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
build-args: CLI_VERSION=${{needs.deploy-cli.outputs.version}} | |
tags: | | |
sokari/allure-deployer:latest | |
sokari/allure-deployer:${{ github.sha }} | |
sokari/allure-deployer:${{needs.deploy-cli.outputs.version}} |