publish to npm (#179) #112
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: Build skandha docker image | |
on: | |
push: | |
branches: | |
- "master" | |
jobs: | |
tag: | |
name: Check tag | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get tag | |
id: get_tag | |
run: echo "tag=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT | |
- name: Assert tag == package.json version | |
run: ./.github/workflows/scripts/assert-same-package-version.sh | |
env: | |
TAG: ${{ steps.get_tag.outputs.tag }} | |
- name: Get previous tag | |
id: get_prev_tag | |
run: node tasks/get_prev_tag.js | |
env: | |
CURRENT_TAG: ${{ steps.get_tag.outputs.tag }} | |
IGNORE_PATTERN: rc | |
outputs: | |
tag: ${{ steps.get_tag.outputs.tag }} | |
prev_tag: ${{ steps.get_prev_tag.outputs.prev_tag }} | |
binaries: | |
name: Build skandha binaries | |
uses: ./.github/workflows/binaries.yml | |
needs: tag | |
with: | |
version: ${{ needs.tag.outputs.tag }} | |
npm: | |
name: Publish to NPM & Github | |
runs-on: ubuntu-latest | |
needs: [tag, binaries] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Needs full depth for changelog generation | |
- name: Install arm64 specifics | |
run: |- | |
# Install missing yarn | |
# See https://github.com/github-early-access/arm-runners-beta/issues/5 | |
curl -fsSL --create-dirs -o $HOME/bin/yarn \ | |
https://github.com/yarnpkg/yarn/releases/download/v1.22.22/yarn-1.22.22.js | |
chmod +x $HOME/bin/yarn | |
echo "$HOME/bin" >> $GITHUB_PATH | |
# Install missing build-essential | |
sudo apt-get update | |
sudo apt-get install -y build-essential | |
- uses: "./.github/actions/setup-and-build" | |
with: | |
node: 20 | |
- name: Get binaries | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist/ | |
merge-multiple: true | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
files: dist/* | |
fail_on_unmatched_files: true | |
tag_name: ${{ needs.tag.outputs.tag }} | |
body_path: "CHANGELOG.md" | |
body: Release ${{ needs.tag.outputs.tag }} | |
name: Release ${{ needs.tag.outputs.tag }} | |
prerelease: false | |
- run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc | |
env: | |
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Publish to npm registry (release) | |
if: ${{ !github.event.act }} # skip during local actions testing | |
run: yarn run release:publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Rollback on failure | |
if: failure() | |
uses: author/action-rollback@9ec72a6af74774e00343c6de3e946b0901c23013 | |
with: | |
id: ${{ steps.create_release.outputs.id }} | |
tag: ${{ needs.tag.outputs.tag }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
docker: | |
if: ${{ !github.event.act }} # skip during local actions testing | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v3 | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- | |
name: Get package version | |
id: get_version | |
run: echo version=$(node -p "require('./package.json').version") >> $GITHUB_OUTPUT | |
- | |
name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
file: ./Dockerfile | |
push: true | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/skandha:${{ steps.get_version.outputs.version }} | |
${{ secrets.DOCKERHUB_USERNAME }}/skandha:latest | |
- | |
name: Trigger pipeline | |
run: ${{ secrets.PIPELINE_TRIGGER }} |