Publish compass-web to NPM and Docker Hub #5
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 compass-web to NPM and Docker Hub | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- 'v*' | |
jobs: | |
publish-npm: | |
permissions: | |
contents: read | |
id-token: write | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.check-version.outputs.version }} | |
is_latest: ${{ steps.check-version.outputs.is_latest }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: 'npm' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Check version | |
id: check-version | |
run: | | |
version=$(node -e "console.log(require('./package.json').version);") | |
if [[ "${{ github.event_name }}" == "push" ]]; then | |
if [[ "${GITHUB_REF##*/v}" != "$version" ]]; then | |
echo "Tag and npm version don't match" | |
exit 1 | |
fi | |
fi | |
echo "version=${version}" >> $GITHUB_OUTPUT | |
if [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "is_latest=true" | |
echo "is_latest=true" >> $GITHUB_OUTPUT | |
else | |
echo "is_latest=false" | |
echo "is_latest=false" >> $GITHUB_OUTPUT | |
fi | |
- run: npm ci | |
- name: Build compass-web | |
run: | | |
NODE_ENV=production npm run build | |
NODE_ENV=production npm run build-server | |
- name: Publish compass-web | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: | | |
version=${{ steps.check-version.outputs.version }} | |
if [[ "$version" == *alpha* ]]; then | |
tag='--tag alpha' | |
elif [[ "$version" == *beta* ]]; then | |
tag='--tag beta' | |
elif [[ "$TAG" == *rc* ]]; then | |
tag='--tag rc' | |
else | |
tag='' | |
fi | |
if [[ "${{ github.event.repository.private }}" == "true" ]]; then | |
provenance='' | |
else | |
provenance='--provenance' | |
fi | |
npm publish ${tag} ${provenance} --access public | |
publish-docker: | |
needs: | |
- publish-npm | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: haohanyang | |
password: ${{ secrets.DOCKER_TOKEN }} | |
- name: Build and push 1 | |
uses: docker/build-push-action@v6 | |
if: ${{ needs.publish-npm.outputs.is_latest == 'true' }} | |
with: | |
push: true | |
tags: haohanyang/compass-web-amd64:${{ needs.publish-npm }} | |
platforms: linux/amd64 | |
build-args: COMPASS_WEB_VERSION=${{ needs.publish-npm.outputs.version }} | |
- name: Build and push 2 | |
uses: docker/build-push-action@v6 | |
if: ${{ needs.publish-npm.outputs.is_latest != 'true' }} | |
with: | |
push: true | |
tags: haohanyang/compass-web-amd64:${{ needs.publish-npm.outputs.version }},haohanyang/compass-web-amd64:latest | |
platforms: linux/amd64 | |
build-args: COMPASS_WEB_VERSION=${{ needs.publish-npm.outputs.version }} |