name: Publish npm packages (reusable) on: workflow_call: inputs: release_type: required: true type: string branch: required: false type: string secrets: gh_token: required: true npm_token: required: true env: # Dagger DAGGER_PLAN: cue.mod/pkg/github.com/3box/pipeline-tools/ci/plans/ceramic.cue DAGGER_LOG_FORMAT: "plain" AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_REGION: ${{ secrets.AWS_DEFAULT_REGION }} AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }} DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} jobs: publish_main: runs-on: ubuntu-latest if: ${{ inputs.release_type == 'main' }} steps: - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 - name: Checkout main branch uses: actions/checkout@v4 with: ref: main token: ${{ secrets.GH_TOKEN }} fetch-depth: 0 - name: Configure git run: | git config user.email "${{ github.actor }}@users.noreply.github.com" git config user.name ${{ github.actor }} git fetch --all - name: Merge down from main -> rc -> develop run: | git checkout -B release-candidate refs/remotes/origin/release-candidate git merge main git checkout -B develop refs/remotes/origin/develop git merge release-candidate git checkout main - name: Merge rc -> main run: git merge release-candidate - name: Initialize and build code run: npm ci && npm run build - name: Publish packages to NPM env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }} run: | npm config set //registry.npmjs.org/:_authToken $NODE_AUTH_TOKEN npm run publish:release -- --yes - name: Send Discord notification run: | # Prepare notification body echo '{"embeds":[{"title":"**Release Published**","description":"' > embed.json echo '' >> embed.json git log -1 --pretty=%B >> embed.json echo '","color":3581519}]}' >> embed.json sed -i '3 s/\ -/-/' embed.json sed -i '4,$ s/\-/\\n-/' embed.json # Send notification res=$(curl -X POST ${{ secrets.DISCORD_RELEASE_WEBHOOK }} -H "Content-Type: application/json" -d @embed.json) || exit 0 - name: Update and push code to rc and develop run: | git checkout release-candidate git pull git merge main git push git checkout develop git pull git merge main git push publish_rc: runs-on: ubuntu-latest if: ${{ inputs.release_type == 'rc' || inputs.release_type == 'rc-followup' }} steps: - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 - name: Checkout rc branch uses: actions/checkout@v4 with: ref: release-candidate token: ${{ secrets.GH_TOKEN }} fetch-depth: 0 - name: Configure git run: | git config user.email "${{ github.actor }}@users.noreply.github.com" git config user.name ${{ github.actor }} git fetch --all - name: Merge down from rc -> develop run: | git checkout -B develop refs/remotes/origin/develop git merge release-candidate git checkout release-candidate - name: Merge develop -> rc run: git merge develop - name: Initialize and build code run: npm ci && npm run build - name: Publish packages to NPM env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }} run: | npm config set //registry.npmjs.org/:_authToken $NODE_AUTH_TOKEN RELEASE_TYPE=${{ inputs.release_type }} if [[ $RELEASE_TYPE == "rc" ]]; then npm run publish:release-candidate -- --yes else # $RELEASE_TYPE == "rc-followup" npm run publish:release-candidate-followup -- --yes fi - name: Send Discord notification run: | # Prepare notification body echo '{"embeds":[{"title":"**Release Candidate Published**","description":"' > embed.json echo '' >> embed.json git log -1 --pretty=%B >> embed.json echo '","color":3581519}]}' >> embed.json sed -i '3 s/\ -/-/' embed.json sed -i '4,$ s/\-/\\n-/' embed.json # Send notification res=$(curl -X POST ${{ secrets.DISCORD_RELEASE_WEBHOOK }} -H "Content-Type: application/json" -d @embed.json) || exit 0 - name: Update and push code to develop run: | git checkout develop git pull git merge release-candidate git push publish_hotfix: runs-on: ubuntu-latest if: ${{ inputs.release_type == 'hotfix' }} steps: - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 - name: Branch check if: ${{ inputs.branch == '' }} run: | echo Hotfix branch must be specified exit 1 - name: Checkout hotfix branch uses: actions/checkout@v4 with: ref: ${{ inputs.branch }} token: ${{ secrets.GH_TOKEN }} # Ref: https://github.com/lerna/lerna/issues/2532 fetch-depth: 0 - name: Configure git run: | git config user.email "${{ github.actor }}@users.noreply.github.com" git config user.name ${{ github.actor }} - name: Initialize and build code run: npm ci && npm run build - name: Publish packages to NPM env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }} run: | npm config set //registry.npmjs.org/:_authToken $NODE_AUTH_TOKEN npm run publish:hotfix -- --yes - name: Send Discord notification run: | # Prepare notification body echo '{"embeds":[{"title":"**Hotfix Published**","description":"' > embed.json echo '' >> embed.json git log -1 --pretty=%B >> embed.json echo '","color":3581519}]}' >> embed.json sed -i '3 s/\ -/-/' embed.json sed -i '4,$ s/\-/\\n-/' embed.json # Send notification res=$(curl -X POST ${{ secrets.DISCORD_RELEASE_WEBHOOK }} -H "Content-Type: application/json" -d @embed.json) || exit 0 - name: Get required envars run: | PROPS=$(dagger do -l error --output-format json version -p ${{ env.DAGGER_PLAN }}) echo "VERSION=$(echo $PROPS | jq -r '.version')" >> $GITHUB_ENV echo "SHA=$(echo $PROPS | jq -r '.sha')" >> $GITHUB_ENV echo "SHA_TAG=$(echo $PROPS | jq -r '.shaTag')" >> $GITHUB_ENV - # Pretend to be the main branch since a hotfix is a patch for the main branch name: Push Docker image run: dagger do push -w "actions:push:\"${{ env.AWS_REGION }}\":prod:main:\"${{ env.SHA }}\":\"${{ env.SHA_TAG }}\":\"${{ env.VERSION }}\":_" -p ${{ env.DAGGER_PLAN }} - name: Create deployment job run: dagger do -l error deploy -w "actions:deploy:\"${{ env.AWS_REGION }}\":prod:\"${{ env.SHA }}\":\"${{ env.SHA_TAG }}\":_" -p ${{ env.DAGGER_PLAN }} publish_nightly: runs-on: ubuntu-latest if: ${{ inputs.release_type == 'nightly' }} steps: - name: Setup Node uses: actions/setup-node@v4 with: node-version: 20 - name: Checkout nightly branch uses: actions/checkout@v4 with: ref: ${{ inputs.branch || 'develop' }} token: ${{ secrets.GH_TOKEN }} # Ref: https://github.com/lerna/lerna/issues/2532 fetch-depth: 0 - name: Configure git run: | git config user.email "${{ github.actor }}@users.noreply.github.com" git config user.name ${{ github.actor }} - name: Initialize and build code run: npm ci && npm run build - # This step explicitly does not push the release commit, so the specified nightly branch will not be impacted. name: Publish all packages to NPM run: | npm config set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }} npm run publish:nightly -- --preid "nightly.$(date +%Y%m%d%H%M%S)" --force-publish --yes