Skip to content

ci: exercise release workflow #45

ci: exercise release workflow

ci: exercise release workflow #45

Workflow file for this run

name: Continuous Integration
on:
push:
branches:
- '*'
tags:
- "v*.*.*"
pull_request:
branches:
- develop
concurrency:
group: ${{format('{0}:{1}', github.repository, github.ref)}}
cancel-in-progress: true
jobs:
build:
strategy:
matrix:
include:
- { name: Windows, os: windows-latest }
- { name: Ubuntu, os: ubuntu-latest }
- { name: MacOS, os: macos-latest }
name: Build (${{ matrix.name }})
runs-on: ${{ matrix.os }}
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Tests
run: npm test
- name: Setup Ninja
if: runner.os == 'Windows'
uses: seanmiddleditch/gha-setup-ninja@v5
- name: Example
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run example
publish-npm:
name: Publish NPM package
needs: [ build ]
runs-on: ubuntu-latest
# Always run the job so non-tag pushes exercise the workflow,
# but gate actual publishing on a semver tag.
env:
IS_TAG: ${{ startsWith(github.ref, 'refs/tags/') }}
steps:
- name: Clone repository
uses: actions/checkout@v4
# Validate tag when it exists
- name: Check version tags
if: env.IS_TAG == 'true'
run: |
GITHUB_TAGNAME=${{ github.ref_name }}
if [[ ! $GITHUB_TAGNAME =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Tag name is not valid. It should match the pattern v*.*.*"
exit 1
fi
PACKAGE_JSON_VERSION=$(node -p "require('./package.json').version")
if [[ $GITHUB_TAGNAME != "v$PACKAGE_JSON_VERSION" ]]; then
echo "Tag name does not match package.json version"
exit 1
fi
echo "IS_SEMVER_TAG=true" >> $GITHUB_ENV
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm ci
- name: Generate README.md
run: |
sudo apt-get update
sudo apt-get install -y pandoc asciidoc-base
asciidoc -b docbook README.adoc
pandoc -f docbook -t markdown README.xml -o README.md --shift-heading-level-by=1 --standalone
rm README.xml
# Include the title as h1
title=$(sed -n 's/^title: \(.*\)/\1/p' README.md)
sed -i '/^---/,/^---/d' README.md
if [ -n "$title" ]; then
sed -i "1s/^/# $title\n\n/" README.md
fi
# Remove attributes from section names
# https://github.com/jgm/pandoc/issues/5965
sed -i -E 's/^(#+ .*?) \{#_[^}]+\}$/\1/' README.md
- name: Publish NPM package
if: env.IS_SEMVER_TAG == 'true'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
continue-on-error: true
- name: Print npm error log
if: env.IS_SEMVER_TAG == 'true' && failure()
run: |
LOG_FILE=$(ls -t /home/runner/.npm/_logs/*.log | head -n 1 || true)
echo "Latest npm debug log file: $LOG_FILE"
if [ -n "$LOG_FILE" ]; then cat "$LOG_FILE"; fi
publish-github:
name: Publish Github Release
needs: [ build, publish-npm ]
runs-on: ubuntu-latest
permissions:
contents: write
env:
IS_TAG: ${{ startsWith(github.ref, 'refs/tags/') }}
steps:
- name: Clone repository
uses: actions/checkout@v4
# Let this run on branches too, so we can test changelog generation
- name: Changelog
uses: alandefreitas/cpp-actions/create-changelog@v1.8.3
with:
thank-non-regular: true
- name: Release
if: env.IS_TAG == 'true'
uses: softprops/action-gh-release@v2
with:
body_path: CHANGELOG.md