Skip to content

Commit

Permalink
Merge pull request #1059 from frontegg/FR-14304-trigger-oauth
Browse files Browse the repository at this point in the history
FR-14304 - Trigger Oauth pipeline after publish
  • Loading branch information
rotemzif1 authored Nov 26, 2023
2 parents ead27db + 37a49b0 commit 10cf80e
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 6 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();
};
36 changes: 32 additions & 4 deletions .github/workflows/publish-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,40 @@ jobs:
const sha = process.env.PR_REF;
const repo = context.payload.repository.name
const owner = context.payload.repository.organization
const res = await github.rest.repos.createCommitStatus({
context, owner, repo, sha,
state: 'pending',
description: 'Dispatching E2E tests...',
});
- name: Wait until NPM registry finished indexing the new version
uses: actions/github-script@v6
with:
script: |
const checkingVersion = '${{ steps.publish_pre_release_version.outputs.LIB_VERSION }}-alpha.${{ github.run_id }}';
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_VERSION: '${{ steps.publish_pre_release_version.outputs.LIB_VERSION }}-alpha.${{ github.run_id }}'
with:
github-token : ${{ secrets.DISPATCH_WORKFLOWS_TOKEN }}
script: |
const fe_react_version= process.env.PR_VERSION;
const owner = context.payload.repository.organization
const oauthServiceRepo = 'oauth-service'
const workflow_id = 'update-react-dependency.yaml'
const data = await github.rest.actions.createWorkflowDispatch({
owner,
repo: oauthServiceRepo,
workflow_id,
ref: 'master',
inputs: {
fe_react_version,
}
});
- name: "Trigger E2E tests"
uses: actions/github-script@v5
env:
Expand All @@ -142,15 +170,15 @@ jobs:
const version = process.env.PR_VERSION;
const sha = process.env.PR_REF;
const repo = context.payload.repository.name
const owner = context.payload.repository.organization
const e2eRepo = 'e2e-system-tests'
const workflow_id = 'frontegg-react-e2e-tests.yml'
const context = `${owner}/${e2eRepo}`
const dispatch_id = `${repo}/${sha}`
const data = await github.rest.actions.createWorkflowDispatch({
owner,
owner,
repo:e2eRepo,
workflow_id,
ref: 'main',
Expand All @@ -159,4 +187,4 @@ jobs:
dispatch_id,
}
});
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ 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_VERSION : '${{ steps.set_current_version.outputs.CURRENT_VERSION }}'
with :
github-token : ${{ secrets.DISPATCH_WORKFLOWS_TOKEN }}
script : |
const fe_react_version= process.env.PR_VERSION;
const owner = context.payload.repository.organization
const oauthServiceRepo = 'oauth-service'
const workflow_id = 'update-react-dependency.yaml'
const data = await github.rest.actions.createWorkflowDispatch({
owner,
repo: oauthServiceRepo,
workflow_id,
ref: 'master',
inputs: {
fe_react_version,
}
});
- name: Notify Slack on deployment
uses: rtCamp/action-slack-notify@v2
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
name: 'Install, Build and Test'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Read .nvmrc
run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
id: nvm
- name: Use Node.js (.nvmrc)
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: "${{ steps.nvm.outputs.NVMRC }}"
- run: make clean
Expand Down

0 comments on commit 10cf80e

Please sign in to comment.