Skip to content
name: Publish to NPM and Docker Hub
on:
release:
types: [ published ]
env:
GIT_TERMINAL_PROMPT: 1
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# Necessary for changelog generation
fetch-depth: 0
- uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- name: Bump version and generate changelog
run: |
tag=${{ github.event.release.tag_name }}
version="${tag//[v]/}"
# Adding version to env for Docker publishing step
echo "VERSION=$version" >> $GITHUB_ENV
git remote update
git fetch
git checkout --track origin/main
git config --global user.email "[email protected]"
git config --global user.name "Github Actions"
npm --no-git-tag-version --allow-same-version version $version
npm i -g auto-changelog
auto-changelog --hide-credit -l 100
git add .
git commit -m "release $version"
git push
- name: Create npm package tarball
run: npm pack
- name: Publish to npm
run: npm publish *.tgz
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Set up QEMU (build against more platforms)
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push image to Docker Hub
uses: docker/build-push-action@v4
with:
context: .
# Using node:18-alpine supported platform
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/json-rpc:latest
${{ secrets.DOCKERHUB_USERNAME }}/json-rpc:${{ env.VERSION }}