Skip to content

NPM Build and publish to npm #109

NPM Build and publish to npm

NPM Build and publish to npm #109

name: NPM Build and publish to npm
on:
schedule:
- cron: '01 00 * * *'# Every day at 00:01 UTC
workflow_dispatch:
inputs:
latest-build:
description: 'Whether to publish as a latest build'
required: true
type: boolean
old-version-patch:
description: 'Whether to publish as a patch to an old version'
required: true
type: boolean
permissions:
id-token: write
contents: read
concurrency:
group: 'npm-audio-package-build'
cancel-in-progress: false
jobs:
build:
if: github.repository == 'software-mansion/react-native-audio-api'
runs-on: ubuntu-latest
environment: deployment
permissions:
contents: read
id-token: write
env:
AUDIO_API_DIR: packages/react-native-audio-api
AUDIO_API_VERSION: PLACEHOLDER # all placeholders to be replaced during the run
TRUNKATED_VERSION: PLACEHOLDER
PACKAGE_NAME: PLACEHOLDER
TAG: PLACEHOLDER
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'yarn'
registry-url: https://registry.npmjs.org/
- name: Update NPM
run: npm install -g npm@latest
- name: Determine version
working-directory: ${{env.AUDIO_API_DIR }}
run: |
VERSION=$(jq -r .version package.json)
echo "AUDIO_API_VERSION=$VERSION" >> $GITHUB_ENV
TRUNKATED_VERSION=$(echo $VERSION | cut -d. -f1,2)
echo "TRUNKATED_VERSION=$TRUNKATED_VERSION" >> $GITHUB_ENV
- name: Assert AUDIO_API_VERSION
if: ${{env.AUDIO_API_VERSION == 'PLACEHOLDER'}}
run: exit 1 # this should never happen
- name: Assert TRUNKATED_VERSION
if: ${{env.TRUNKATED_VERSION == 'PLACEHOLDER'}}
run: exit 1 # this should never happen
- name: Install monorepo dependencies
run: yarn install --immutable
- name: Set tag
run: |
if [[ "${{inputs.old-version-patch }}" == "true" ]]; then
CURRENT_VERSION=$(npm view react-native-audio-api version | cut -d. -f1,2)
if [[ "$CURRENT_VERSION" == "${{env.TRUNKATED_VERSION }}" ]]; then
echo "Old version patch requested but current published version matches package version. Exiting."
exit 1
fi
echo "TAG=rn-audio-api-${{env.TRUNKATED_VERSION }}" >> $GITHUB_ENV
elif [[ "${{inputs.latest-build }}" != "true" ]]; then
echo "TAG=audio-api-nightly" >> $GITHUB_ENV
else
echo "TAG=latest" >> $GITHUB_ENV
fi
- name: Assert tag
if: ${{env.TAG == 'PLACEHOLDER'}}
run: exit 1 # this should never happen
- name: Build package
id: build
working-directory: ${{env.AUDIO_API_DIR }}
run: |
if [[ "${{inputs.latest-build }}" != "true" && "${{inputs.old-version-patch }}" != "true"]]; then
./scripts/create-package.sh generate_nightly_version
else
./scripts/create-package.sh
fi
- name: Check if any node_modules were packed
id: check_node_modules
working-directory: ${{env.AUDIO_API_DIR }}
run: >-
! grep --silent -E "node_modules/.+" build.log
- name: Show build log
working-directory: ${{env.AUDIO_API_DIR }}
if: failure() && steps.build.outcome == 'failure'
run: cat build.log
- name: Show packed node_modules
working-directory: ${{env.AUDIO_API_DIR }}
if: failure() && steps.node_modules.outcome == 'failure'
run: >-
! grep -E "node_modules/.+" build.log
- name: Add package name to env
working-directory: ${{env.AUDIO_API_DIR }}
run: echo "PACKAGE_NAME=$(ls -l | egrep -o "react-native-audio-api-(.*)(=?\.tgz)")" >> $GITHUB_ENV
- name: Assert package name
if: ${{env.PACKAGE_NAME == 'PLACEHOLDER'}}
run: exit 1 # this should never happen
- name: Upload package to GitHub
uses: actions/upload-artifact@v4
with:
name: ${{env.PACKAGE_NAME }}
path: ${{env.AUDIO_API_DIR }}/${{env.PACKAGE_NAME }}
- name: Move package to monorepo root
run: mv ${{env.AUDIO_API_DIR }}/${{env.PACKAGE_NAME }} .
- name: Publish package to npm
run: npm publish $PACKAGE_NAME --tag ${{env.TAG }} --provenance