Skip to content

ci: update of files from global .github repo (#865) #15

ci: update of files from global .github repo (#865)

ci: update of files from global .github repo (#865) #15

# It does magic only if there is a package.json file in the root of the project
name: Release - if Node project
on:
push:
branches:
- master
jobs:
test-nodejs:
name: Test NodeJS PR - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Using macos-13 instead of latest (macos-14) due to an issue with Puppeteer and such runner.
# See: https://github.com/puppeteer/puppeteer/issues/12327 and https://github.com/asyncapi/parser-js/issues/1001
os: [ubuntu-latest, macos-13, windows-latest]
steps:
- id: should_run
name: Should Run
run: echo "shouldrun=true" >> $GITHUB_OUTPUT
shell: bash
- if: steps.should_run.outputs.shouldrun == 'true'
name: Set git to use LF #to once and for all finish neverending fight between Unix and Windows
run: |
git config --global core.autocrlf false
git config --global core.eol lf
shell: bash
- if: steps.should_run.outputs.shouldrun == 'true'
name: Checkout repository
uses: actions/checkout@v4
- if: steps.should_run.outputs.shouldrun == 'true'
name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- if: steps.should_run.outputs.shouldrun == 'true'
uses: pnpm/action-setup@v3
with:
run_install: false
- if: steps.should_run.outputs.shouldrun == 'true'
name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- if: steps.should_run.outputs.shouldrun == 'true'
uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- if: steps.should_run.outputs.shouldrun == 'true'
name: Install dependencies
shell: bash
run: pnpm install
- if: steps.should_run.outputs.shouldrun == 'true'
name: Test
run: pnpm test
release:
needs: [test-nodejs]
name: Publish to any of NPM, GitHub, or Docker Hub
runs-on: ubuntu-latest
steps:
- name: Set git to use LF # To once and for all finish the never-ending fight between Unix and Windows
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout repository
uses: actions/checkout@v4
- name: Check if Node.js project and has package.json
id: packagejson
run: test -e ./package.json && echo "exists=true" >> $GITHUB_OUTPUT || echo "exists=false" >> $GITHUB_OUTPUT
shell: bash
- if: steps.packagejson.outputs.exists == 'true'
name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.0.0"
- if: steps.packagejson.outputs.exists == 'true'
uses: pnpm/action-setup@v3
with:
run_install: false
- if: steps.packagejson.outputs.exists == 'true'
name: Install dependencies
shell: bash
run: pnpm install --frozen-lockfile
- if: steps.packagejson.outputs.exists == 'true'
name: Build dependency
shell: bash
run: pnpm run build
- if: steps.packagejson.outputs.exists == 'true'
name: Install changelog
shell: bash
run: pnpm install --workspace-root @changesets/changelog-git@0.2.0
- if: steps.packagejson.outputs.exists == 'true'
name: Publish to any of NPM, Github, and Docker Hub
uses: changesets/action@v1
id: release
with:
version: npx -p @changesets/cli changeset version
commit: version packages
title: "chore(release): version packages"
publish: npx -p @changesets/cli changeset publish
setupGitUser: false
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
GIT_AUTHOR_NAME: asyncapi-bot
GIT_AUTHOR_EMAIL: info@asyncapi.io
GIT_COMMITTER_NAME: asyncapi-bot
GIT_COMMITTER_EMAIL: info@asyncapi.io
- if: failure() # Only, on failure, send a message on the 94_bot-failing-ci Slack channel
name: Report workflow run status to Slack
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,action,workflow
text: "Release workflow failed in release job"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_FAIL_NOTIFY }}