ci: automate patch releases and npm publishing #50
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: Node.js CI | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
release: | |
types: | |
- created | |
env: | |
ESM_NAME: "@ohri/openmrs-esm-rwanda" | |
JS_NAME: "openmrs-esm-rwanda.js" | |
jobs: | |
build: | |
name: Build and Test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.x" | |
- run: yarn install --immutable | |
- run: yarn verify | |
- run: yarn build | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dist | |
path: dist | |
patch_release: | |
name: Patch Release | |
runs-on: ubuntu-latest | |
needs: build | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v3 | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.x" | |
registry-url: "https://registry.npmjs.org" | |
- run: yarn install --immutable | |
- name: Git Config | |
run: | | |
git config --global user.name "GitHub Actions Bot" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Bump Patch Version and Publish | |
shell: bash | |
run: | | |
echo "Bumping patch version for main branch..." | |
git pull origin main | |
yarn plugin import version | |
yarn version patch | |
NEW_VERSION=$(node -p "require('./package.json').version") | |
echo "Version bumped to: $NEW_VERSION" | |
git push origin main --tags | |
echo "Publishing patch release to NPM..." | |
yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" | |
yarn npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
release: | |
name: Publish Release | |
runs-on: ubuntu-latest | |
needs: build | |
if: ${{ github.event_name == 'release' }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v3 | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.x" | |
registry-url: "https://registry.npmjs.org" | |
- run: yarn install --immutable | |
- name: Publish Release Version | |
run: | | |
echo "Publishing release version..." | |
TAG_VERSION=${{ github.event.release.tag_name }} | |
if [ -z "$TAG_VERSION" ]; then | |
echo "Error: TAG_VERSION is empty." | |
exit 1 | |
fi | |
echo "Using release tag: $TAG_VERSION" | |
CURRENT_VERSION=$(node -p "require('./package.json').version") | |
if [ "$CURRENT_VERSION" != "$TAG_VERSION" ]; then | |
echo "Error: Version mismatch - package.json ($CURRENT_VERSION) vs. tag ($TAG_VERSION)." | |
exit 1 | |
fi | |
yarn config set npmAuthToken "${NODE_AUTH_TOKEN}" | |
yarn npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
deploy: | |
name: Deployment | |
runs-on: ubuntu-latest | |
needs: patch_release | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} | |
steps: | |
- name: Trigger RefApp Build | |
run: echo "No deployment configured. Skipping." | |
# Uncomment and configure the following lines to trigger your build: | |
# - uses: fjogeleit/http-request-action@master | |
# with: | |
# url: https://ci.openmrs.org/rest/api/latest/queue/REFAPP-D3X | |
# method: "POST" | |
# customHeaders: '{ "Authorization": "Bearer ${{ secrets.BAMBOO_TOKEN }}" }' |