NPM Build and publish to npm #2
This file contains hidden or 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: NPM Build and publish to npm | |
on: | |
workflow_call: | |
inputs: | |
nightly-build: | |
required: true | |
type: boolean | |
workflow_dispatch: | |
jobs: | |
build: | |
if: github.repository == 'software-mansion/react-native-audio-api' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
id-token: write | |
env: | |
AUDIO_API_DIR: packages/react-native-audio-api | |
AUDIO_API_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: Determine version | |
working-directory: ${{ env.AUDIO_API_DIR }} | |
run: | | |
VERSION=$(jq -r .version package.json) | |
echo "AUDIO_API_VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Assert AUDIO_API_VERSION | |
if: ${{ env.AUDIO_API_VERSION == 'PLACEHOLDER' }} | |
run: exit 1 # this should never happen | |
- name: Install monorepo dependencies | |
run: yarn install --immutable | |
- name: Set tag | |
run: | | |
if [[ "${{ inputs.nightly-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.nightly-build }}" == "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 | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }} |