Skip to content

Commit

Permalink
FR-15672-e2e-workflows-support
Browse files Browse the repository at this point in the history
  • Loading branch information
doregg committed Mar 20, 2024
1 parent 00883bf commit 56f80cf
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/actions/trigger-e2e-test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Trigger E2E Action
description: Trigger E2E workflow for a specific version
# this is used manually (workflow action) and automatically (merge to master)

inputs:
version:
description: 'Version'
required: true
sha:
description: 'Commit SHA'
required: true
bot_app_id:
description: 'Bot App Id'
required: true
bot_app_key:
description: 'Bot App Key'
required: true

runs:
using: "composite"
steps:
- id: create_bot_token
name: Create bot token
uses: wow-actions/use-app-token@v2
with:
app_id: ${{ inputs.bot_app_id }}
private_key: ${{ inputs.bot_app_key }}
- name: "Trigger E2E tests"
uses: actions/github-script@v5
env:
version: ${{ inputs.version }}
sha: ${{ inputs.sha }}
with:
github-token: ${{ steps.create_bot_token.outputs.BOT_TOKEN }}
script: |
const {sha, version} = process.env;
const repo = 'frontegg-angular'
const owner = 'frontegg'
const e2eRepo = 'e2e-system-tests'
const workflow_id = 'frontegg-react-e2e-tests.yml' // should be renamed in a later phase
const dispatch_id = `${repo}/${sha}`
github.rest.actions.createWorkflowDispatch({
owner,
repo: e2eRepo,
workflow_id,
ref: 'master',
inputs: {
version,
dispatch_id,
}
})
19 changes: 19 additions & 0 deletions .github/workflows/publish-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ jobs:
return version;
- name: Commit changes
shell: bash -ex {0}
id: 'cpr_commit_sha'
run: |
git add . && git commit -m "chore(release): publish ${{ steps.incremented-version.outputs.result }}"
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Create Release Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3.5.1
Expand Down Expand Up @@ -115,3 +118,19 @@ jobs:
SLACK_USERNAME : ${{ github.actor }}
SLACK_WEBHOOK : ${{ secrets.ROTEM_SLACK_WEBHOOK }}
MSG_MINIMAL : true

- 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/angular'], checkingVersion);
- name: "Call trigger-e2e-test action"
uses: ./.github/actions/trigger-e2e-test
with:
version: ${{ steps.publish_pre_release_version.outputs.LIB_VERSION }}-alpha.${{ github.run_id }}
sha: ${{ steps.cpr_commit_sha.outputs.sha }}
bot_app_id: ${{ secrets.GH_FRONTEGG_BOT_APP_ID }}
bot_app_key: ${{ secrets.GH_FRONTEGG_BOT_APP_SECRET }}
31 changes: 31 additions & 0 deletions .github/workflows/trigger-e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "(▶) Trigger E2E tests Workflow"

on:
workflow_dispatch:
inputs:
version:
description: 'Version'
required: true
sha:
description: 'Commit SHA'
required: true

jobs:
trigger_e2e_tests:
name: "Trigger E2E tests Workflow"
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@v4

- name: "Print inputs"
run: |
echo "Received test request for @frontegg/angular@${{ inputs.version }}"
echo "From: ${{ inputs.sha }}"
- name: "Call trigger-e2e-test action"
uses: ./.github/actions/trigger-e2e-test
with:
version: ${{ inputs.version }}
sha: ${{ inputs.sha }}
bot_app_id: ${{ secrets.GH_FRONTEGG_BOT_APP_ID }}
bot_app_key: ${{ secrets.GH_FRONTEGG_BOT_APP_SECRET }}
37 changes: 37 additions & 0 deletions scripts/wait-for-npm-indexing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* 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) {
console.log(`Waiting for publish of version ${version} of ${packages[i]}`)
try {
const result = JSON.parse(execSync(`npm show ${packages[i]} --json dist-tags`).toString('utf8').trim());
console.log("Found versions: ", result)
allPackagesIndexed = allPackagesIndexed && (result.alpha === version || result.next === 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();
};

0 comments on commit 56f80cf

Please sign in to comment.