Publish to NPM #72
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/[email protected] | |
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/[email protected] | |
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/[email protected] | |
with: | |
author_name: Sokari | |
author_email: [email protected] | |
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/[email protected] | |
- 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/login-action@v3 | |
with: | |
username: ${{ vars.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/[email protected] | |
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}} |