diff --git a/.github/scripts/wait-for-npm-indexing.js b/.github/scripts/wait-for-npm-indexing.js new file mode 100644 index 000000000..5a01f45c9 --- /dev/null +++ b/.github/scripts/wait-for-npm-indexing.js @@ -0,0 +1,34 @@ +/* eslint-disable no-undef,@typescript-eslint/no-var-requires */ +const { execSync } = require('child_process'); + +const delay = () => new Promise(resolve => setTimeout(() => resolve(), 1000)); + +module.exports = async (github, packages, version) => { + let timeout = 60; + + const checkPackages = async () => { + if (timeout === 0) { + throw Error('TIMEOUT: Some packages does not appear in NPM registry'); + } + + let allPackagesIndexed = true; + + for (let i in packages) { + try { + const result = JSON.parse(execSync(`npm show ${packages[i]} --json dist-tags`).toString('utf8').trim()); + allPackagesIndexed = allPackagesIndexed && (result.alpha === version || result.latest === version); + } catch (e) { + console.error('Failed to check version for', packages[i], e); + allPackagesIndexed = false; + } + } + + if (!allPackagesIndexed) { + timeout--; + await delay(); + await checkPackages(); + } + }; + + await checkPackages(); +}; diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1bc0629ee..8628ea08f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -99,6 +99,38 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }} + - name : Wait until NPM registry finished indexing the new version + uses : actions/github-script@v6 + with : + script : | + const checkingVersion = '${{ steps.set_current_version.outputs.CURRENT_VERSION }}'; + const checkNpmVersions = require('./scripts/wait-for-npm-indexing.js'); + await checkNpmVersions(github, ['@frontegg/react'], checkingVersion); + - name : "Trigger Oauth Service Pipeline Workflow" + uses : actions/github-script@v5 + env : + PR_REF : '${{ steps.cpr.outputs.pull-request-head-sha }}' + PR_VERSION : '${{ steps.set_current_version.outputs.CURRENT_VERSION }}' + with : + github-token : ${{ secrets.E2E_WORKFLOW_TOKEN }} #TODO: get the token from Guy + script : | + const {repo, sha, version} = process.env; + const owner = context.payload.repository.organization + const oauthServiceRepo = 'oauth-service' + const workflow_id = 'update-react-dependency.yaml' + const context = `${owner}/${oauthServiceRepo}` + const dispatch_id = `${repo}/${sha}` + + const data = await github.rest.actions.createWorkflowDispatch({ + owner, + repo:oauthServiceRepo, + workflow_id, + ref: 'main', + inputs: { + version, + dispatch_id, + } + }); - name: Notify Slack on deployment uses: rtCamp/action-slack-notify@v2 env: