Publish packages #2342
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: "Publish packages" | |
| on: | |
| release: | |
| types: [released] | |
| # Release is not triggered when the release was created by another workflow using GITHUB_TOKEN https://github.com/orgs/community/discussions/25281#discussioncomment-3300251 | |
| workflow_run: | |
| workflows: [Create release] | |
| types: | |
| - completed | |
| workflow_dispatch: # Allows manual triggering | |
| inputs: | |
| release_tag: | |
| description: "The release tag to checkout" | |
| required: true | |
| jobs: | |
| publish-react: | |
| name: "[⚛️ REACT] Publish to npm" | |
| # Prevents running on the release-please branch | |
| # For workflow_run trigger we need to check if the workflow_run was successful and if the new_version output was set to not run on it if no new version was released | |
| if: | | |
| contains(github.event.release.tag_name, 'react-v') && | |
| github.head_ref != 'release-please--branches--master' && !contains(github.event.pull_request.labels.*.name, 'autorelease') && | |
| github.event_name == 'workflow_dispatch' || github.event_name == 'release' || | |
| (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.outputs.new_version) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.release.tag_name || github.event.inputs.release_tag || github.sha }} # Checkout the tagged release | |
| - uses: ./.github/actions/publish-to-npmjs | |
| id: publish | |
| with: | |
| workspace: "@factorialco/f0-react" | |
| registry_token: ${{ secrets.NPMJS_TOKEN }} | |
| - name: Notify Slack | |
| if: ${{ steps.publish.outputs.published == 'true' }} | |
| env: | |
| RELEASE_BODY_RAW: ${{ github.event.release.body }} | |
| RELEASE_URL: ${{ github.event.release.html_url }} | |
| RELEASE_NAME: ${{ github.event.release.name }} | |
| PACKAGE: "@factorialco/f0-react" | |
| NPM_URL: "https://www.npmjs.com/package/@factorialco/f0-react?activeTab=versions" | |
| run: | | |
| # 1️⃣ Convert GitHub-style markdown ➜ Slack mrkdwn | |
| RELEASE_BODY=$(echo "$RELEASE_BODY_RAW" | perl -pe ' | |
| s/^### (.+)$/*\1*/; # h3 ➜ bold | |
| s/^## (.+)$/*\1*/; # h2 ➜ bold | |
| s/^(\s*[-*])\s+/• /; # bullets | |
| s/\[([^\]]+)\]\(([^)]+)\)/<\2|\1>/g; # links | |
| ') | |
| # 2️⃣ JSON-escape the body (newline-preserving) | |
| BODY_JSON=$(printf "%s" "$RELEASE_BODY" | jq -Rs .) | |
| # 3️⃣ Build Block-Kit payload with jq | |
| jq -n --arg body "$RELEASE_BODY" \ | |
| --arg rel_url "$RELEASE_URL" \ | |
| --arg rel_name "$RELEASE_NAME" \ | |
| --arg npm "$NPM_URL" \ | |
| --arg pkg "$PACKAGE" ' | |
| { | |
| blocks: [ | |
| { type: "header", | |
| text: { type: "plain_text", text: "⚛️ New version \($rel_name) released" } }, | |
| { type: "section", | |
| text: { type: "mrkdwn", text: $body } }, | |
| { type: "context", | |
| elements: [ | |
| { type: "mrkdwn", text: "<\($npm)|npm package>" }, | |
| { type: "mrkdwn", text: "<\($rel_url)|GitHub release>" } | |
| ] } | |
| ] | |
| }' > /tmp/payload.json | |
| # 4️⃣ Send | |
| curl -X POST -H "Content-Type: application/json" \ | |
| --data @/tmp/payload.json \ | |
| "${{ secrets.SLACK_WEBHOOK_ZERO_UPDATER }}" | |
| publish-react-native: | |
| name: "[📱 REACT NATIVE] Publish to npm" | |
| # Prevents running on the release-please branch | |
| # For workflow_run trigger we need to check if the workflow_run was successful and if the new_version output was set to not run on it if no new version was released | |
| if: | | |
| contains(github.event.release.tag_name, 'react-native-v') && | |
| github.head_ref != 'release-please--branches--master' && !contains(github.event.pull_request.labels.*.name, 'autorelease') && | |
| github.event_name == 'workflow_dispatch' || github.event_name == 'release' || | |
| (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.outputs.new_version) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.release.tag_name || github.event.inputs.release_tag || github.sha }} # Checkout the tagged release | |
| - uses: ./.github/actions/publish-to-npmjs | |
| id: publish | |
| with: | |
| workspace: "@factorialco/f0-react-native" | |
| registry_token: ${{ secrets.NPMJS_TOKEN }} | |
| - name: Notify Slack | |
| if: ${{ steps.publish.outputs.published == 'true' }} | |
| env: | |
| RELEASE_BODY_RAW: ${{ github.event.release.body }} | |
| RELEASE_URL: ${{ github.event.release.html_url }} | |
| RELEASE_NAME: ${{ github.event.release.name }} | |
| PACKAGE: "@factorialco/f0-react-native" | |
| NPM_URL: "https://www.npmjs.com/package/@factorialco/f0-react-native?activeTab=versions" | |
| run: | | |
| # 1️⃣ Convert GitHub-style markdown ➜ Slack mrkdwn | |
| RELEASE_BODY=$(echo "$RELEASE_BODY_RAW" | perl -pe ' | |
| s/^### (.+)$/*\1*/; # h3 ➜ bold | |
| s/^## (.+)$/*\1*/; # h2 ➜ bold | |
| s/^(\s*[-*])\s+/• /; # bullets | |
| s/\[([^\]]+)\]\(([^)]+)\)/<\2|\1>/g; # links | |
| ') | |
| # 2️⃣ JSON-escape the body (newline-preserving) | |
| BODY_JSON=$(printf "%s" "$RELEASE_BODY" | jq -Rs .) | |
| # 3️⃣ Build Block-Kit payload with jq | |
| jq -n --arg body "$RELEASE_BODY" \ | |
| --arg rel_url "$RELEASE_URL" \ | |
| --arg rel_name "$RELEASE_NAME" \ | |
| --arg npm "$NPM_URL" \ | |
| --arg pkg "$PACKAGE" ' | |
| { | |
| blocks: [ | |
| { type: "header", | |
| text: { type: "plain_text", text: "📱 New version \($rel_name) released" } }, | |
| { type: "section", | |
| text: { type: "mrkdwn", text: $body } }, | |
| { type: "context", | |
| elements: [ | |
| { type: "mrkdwn", text: "<\($npm)|npm package>" }, | |
| { type: "mrkdwn", text: "<\($rel_url)|GitHub release>" } | |
| ] } | |
| ] | |
| }' > /tmp/payload.json | |
| # 4️⃣ Send | |
| curl -X POST -H "Content-Type: application/json" \ | |
| --data @/tmp/payload.json \ | |
| "${{ secrets.SLACK_WEBHOOK_ZERO_UPDATER }}" | |
| publish-core: | |
| name: "[🎯 CORE] Publish to npm" | |
| # Prevents running on the release-please branch | |
| # For workflow_run trigger we need to check if the workflow_run was successful and if the new_version output was set to not run on it if no new version was released | |
| if: | | |
| contains(github.event.release.tag_name, 'core-v') && | |
| github.head_ref != 'release-please--branches--master' && !contains(github.event.pull_request.labels.*.name, 'autorelease') && | |
| github.event_name == 'workflow_dispatch' || github.event_name == 'release' || | |
| (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.outputs.new_version) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ github.event.release.tag_name || github.event.inputs.release_tag || github.sha }} # Checkout the tagged release | |
| - uses: ./.github/actions/publish-to-npmjs | |
| id: publish | |
| with: | |
| workspace: "@factorialco/f0-core" | |
| registry_token: ${{ secrets.NPMJS_TOKEN }} | |
| - name: Notify Slack | |
| if: ${{ steps.publish.outputs.published == 'true' }} | |
| env: | |
| RELEASE_BODY_RAW: ${{ github.event.release.body }} | |
| RELEASE_URL: ${{ github.event.release.html_url }} | |
| RELEASE_NAME: ${{ github.event.release.name }} | |
| PACKAGE: "@factorialco/f0-core" | |
| NPM_URL: "https://www.npmjs.com/package/@factorialco/f0-core?activeTab=versions" | |
| run: | | |
| # 1️⃣ Convert GitHub-style markdown ➜ Slack mrkdwn | |
| RELEASE_BODY=$(echo "$RELEASE_BODY_RAW" | perl -pe ' | |
| s/^### (.+)$/*\1*/; # h3 ➜ bold | |
| s/^## (.+)$/*\1*/; # h2 ➜ bold | |
| s/^(\s*[-*])\s+/• /; # bullets | |
| s/\[([^\]]+)\]\(([^)]+)\)/<\2|\1>/g; # links | |
| ') | |
| # 2️⃣ JSON-escape the body (newline-preserving) | |
| BODY_JSON=$(printf "%s" "$RELEASE_BODY" | jq -Rs .) | |
| # 3️⃣ Build Block-Kit payload with jq | |
| jq -n --arg body "$RELEASE_BODY" \ | |
| --arg rel_url "$RELEASE_URL" \ | |
| --arg rel_name "$RELEASE_NAME" \ | |
| --arg npm "$NPM_URL" \ | |
| --arg pkg "$PACKAGE" ' | |
| { | |
| blocks: [ | |
| { type: "header", | |
| text: { type: "plain_text", text: "🎯 New version \($rel_name) released" } }, | |
| { type: "section", | |
| text: { type: "mrkdwn", text: $body } }, | |
| { type: "context", | |
| elements: [ | |
| { type: "mrkdwn", text: "<\($npm)|npm package>" }, | |
| { type: "mrkdwn", text: "<\($rel_url)|GitHub release>" } | |
| ] } | |
| ] | |
| }' > /tmp/payload.json | |
| # 4️⃣ Send | |
| curl -X POST -H "Content-Type: application/json" \ | |
| --data @/tmp/payload.json \ | |
| "${{ secrets.SLACK_WEBHOOK_ZERO_UPDATER }}" |