Skip to content

Commit

Permalink
FR-14304 - Trigger oauth pipeline after publish
Browse files Browse the repository at this point in the history
  • Loading branch information
rotemzif1 committed Nov 26, 2023
1 parent fc3cb5f commit b739832
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/scripts/wait-for-npm-indexing.js
Original file line number Diff line number Diff line change
@@ -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();
};
32 changes: 32 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b739832

Please sign in to comment.