|
| 1 | +name: NPM Build and publish to npm |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '01 00 * * *' # Every day at 00:01 UTC |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + latest-build: |
| 9 | + description: 'Whether to publish as a latest build' |
| 10 | + required: true |
| 11 | + type: boolean |
| 12 | + old-version-patch: |
| 13 | + description: 'Whether to publish as a patch to an old version' |
| 14 | + required: true |
| 15 | + type: boolean |
| 16 | + |
| 17 | +permissions: |
| 18 | + id-token: write |
| 19 | + contents: read |
| 20 | + |
| 21 | +concurrency: |
| 22 | + group: 'npm-audio-package-build' |
| 23 | + cancel-in-progress: false |
| 24 | + |
| 25 | +jobs: |
| 26 | + build: |
| 27 | + if: github.repository == 'software-mansion/react-native-audio-api' |
| 28 | + runs-on: ubuntu-latest |
| 29 | + environment: deployment |
| 30 | + permissions: |
| 31 | + contents: read |
| 32 | + id-token: write |
| 33 | + env: |
| 34 | + AUDIO_API_DIR: packages/react-native-audio-api |
| 35 | + AUDIO_API_VERSION: PLACEHOLDER |
| 36 | + PACKAGE_NAME: PLACEHOLDER |
| 37 | + TAG: PLACEHOLDER |
| 38 | + steps: |
| 39 | + - name: Checkout |
| 40 | + uses: actions/checkout@v4 |
| 41 | + |
| 42 | + - name: Setup Node |
| 43 | + uses: actions/setup-node@v4 |
| 44 | + with: |
| 45 | + node-version: 22 |
| 46 | + cache: 'yarn' |
| 47 | + registry-url: https://registry.npmjs.org/ |
| 48 | + |
| 49 | + - name: Update NPM |
| 50 | + run: npm install -g npm@latest |
| 51 | + |
| 52 | + - name: Determine version |
| 53 | + working-directory: ${{ env.AUDIO_API_DIR }} |
| 54 | + run: | |
| 55 | + VERSION=$(jq -r .version package.json) |
| 56 | + echo "AUDIO_API_VERSION=$VERSION" >> $GITHUB_ENV |
| 57 | + TRUNKATED_VERSION=$(echo $VERSION | cut -d. -f1,2) |
| 58 | + echo "TRUNKATED_VERSION=$TRUNKATED_VERSION" >> $GITHUB_ENV |
| 59 | +
|
| 60 | + - name: Assert AUDIO_API_VERSION |
| 61 | + if: ${{ env.AUDIO_API_VERSION == 'PLACEHOLDER' }} |
| 62 | + run: exit 1 # this should never happen |
| 63 | + |
| 64 | + - name: Assert TRUNKATED_VERSION |
| 65 | + if: ${{ env.TRUNKATED_VERSION == 'PLACEHOLDER' }} |
| 66 | + run: exit 1 # this should never happen |
| 67 | + |
| 68 | + - name: Install monorepo dependencies |
| 69 | + run: yarn install --immutable |
| 70 | + |
| 71 | + - name: Set tag |
| 72 | + run: | |
| 73 | + if [[ "${{ inputs.latest-build }}" != "true" ]]; then |
| 74 | + echo "TAG=audio-api-nightly" >> $GITHUB_ENV |
| 75 | + else if [[ "${{ inputs.old-version-patch }}" == "true" ]]; then |
| 76 | + CURRENT_VERSION=$(npm view react-native-audio-api version | cut -d. -f1,2) |
| 77 | + if [[ "$CURRENT_VERSION" == "${{ env.TRUNKATED_VERSION }}" ]]; then |
| 78 | + echo "Old version patch requested but current published version matches package version. Exiting." |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + echo "TAG=rn-audio-api-$TRUNKATED_VERSION" >> $GITHUB_ENV |
| 82 | + else |
| 83 | + echo "TAG=latest" >> $GITHUB_ENV |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Assert tag |
| 87 | + if: ${{ env.TAG == 'PLACEHOLDER' }} |
| 88 | + run: exit 1 # this should never happen |
| 89 | + |
| 90 | + - name: Build package |
| 91 | + id: build |
| 92 | + working-directory: ${{ env.AUDIO_API_DIR }} |
| 93 | + run: | |
| 94 | + if [[ "${{ inputs.latest-build }}" != "true" ]]; then |
| 95 | + ./scripts/create-package.sh generate_nightly_version |
| 96 | + else |
| 97 | + ./scripts/create-package.sh |
| 98 | + fi |
| 99 | +
|
| 100 | + - name: Check if any node_modules were packed |
| 101 | + id: check_node_modules |
| 102 | + working-directory: ${{ env.AUDIO_API_DIR }} |
| 103 | + run: >- |
| 104 | + ! grep --silent -E "node_modules/.+" build.log |
| 105 | +
|
| 106 | + - name: Show build log |
| 107 | + working-directory: ${{ env.AUDIO_API_DIR }} |
| 108 | + if: failure() && steps.build.outcome == 'failure' |
| 109 | + run: cat build.log |
| 110 | + |
| 111 | + - name: Show packed node_modules |
| 112 | + working-directory: ${{ env.AUDIO_API_DIR }} |
| 113 | + if: failure() && steps.node_modules.outcome == 'failure' |
| 114 | + run: >- |
| 115 | + ! grep -E "node_modules/.+" build.log |
| 116 | +
|
| 117 | + - name: Add package name to env |
| 118 | + working-directory: ${{ env.AUDIO_API_DIR }} |
| 119 | + run: echo "PACKAGE_NAME=$(ls -l | egrep -o "react-native-audio-api-(.*)(=?\.tgz)")" >> $GITHUB_ENV |
| 120 | + |
| 121 | + - name: Assert package name |
| 122 | + if: ${{ env.PACKAGE_NAME == 'PLACEHOLDER' }} |
| 123 | + run: exit 1 # this should never happen |
| 124 | + |
| 125 | + - name: Upload package to GitHub |
| 126 | + uses: actions/upload-artifact@v4 |
| 127 | + with: |
| 128 | + name: ${{ env.PACKAGE_NAME }} |
| 129 | + path: ${{ env.AUDIO_API_DIR }}/${{ env.PACKAGE_NAME }} |
| 130 | + |
| 131 | + - name: Move package to monorepo root |
| 132 | + run: mv ${{ env.AUDIO_API_DIR }}/${{ env.PACKAGE_NAME }} . |
| 133 | + |
| 134 | + - name: Publish package to npm |
| 135 | + run: npm publish $PACKAGE_NAME --tag ${{ env.TAG }} --provenance |
0 commit comments