Skip to content

Main Workflow

Main Workflow #14

Workflow file for this run

name: Main Workflow
permissions:
actions: write
contents: write
statuses: write
pull-requests: write
on:
workflow_dispatch:
inputs:
dispatchId:
type: string
depth:
type: number
default: 1
max-depth:
type: number
default: 1
website-url:
type: string
required: true
previous-file:
type: string
description: Previous test yaml file to use as a base
login_username:
type: string
description: Username
login_password:
type: string
description: Username
workflow_call:
inputs:
dispatchId:
type: string
depth:
type: number
default: 1
max-depth:
type: number
default: 1
website-url:
type: string
required: true
previous-file:
type: string
description: Previous test yaml file to use as a base
login_username:
type: string
description: Username
login_password:
type: string
description: Username
secrets:
TESTDRIVER_API_KEY:
required: true
GH_TOKEN:
required: true
jobs:
match-dispatchId:
if: ${{ inputs.dispatchId }}
runs-on: [ubuntu-latest]
steps:
- id: dispatch-id
name: dispatchId:${{ inputs.dispatchId }}
run: echo "💁 The dispatch ID is ${{ github.event.inputs.dispatchId }}"
- name: Mask secret
run: echo "::add-mask::${{ inputs.login_password }}"
generate-exploratory:
needs: match-dispatchId
uses: ./.github/workflows/generate-exploratory.yml
with:
depth: ${{ fromJson(inputs.depth) }}
max-depth: ${{ fromJson(inputs.max-depth) }}
website-url: ${{ inputs.website-url }}
base-branch: ${{ github.ref_name }}
previous-file: ${{ inputs.previous-file }}
secrets:
TESTDRIVER_API_KEY: ${{ secrets.TESTDRIVER_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LOGIN_USERNAME: ${{ inputs.login_username }}
LOGIN_PASSWORD: ${{ inputs.login_password }}
generate-regression:
needs: generate-exploratory
uses: ./.github/workflows/generate-regressions.yml
with:
depth: ${{ fromJson(inputs.depth) }}
max-depth: ${{ fromJson(inputs.max-depth) }}
website-url: ${{ inputs.website-url }}
base-branch: ${{ needs.generate-exploratory.outputs.pr-branch }}
secrets:
TESTDRIVER_API_KEY: ${{ secrets.TESTDRIVER_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LOGIN_USERNAME: ${{ inputs.login_username }}
LOGIN_PASSWORD: ${{ inputs.login_password }}
generate-next-depth:
if: ${{inputs.depth != inputs.max-depth}}
name: Trigger Next Level
needs: generate-regression
runs-on: ubuntu-latest
steps:
- name: Trigger Next Depth of Workflows
if: ${{ inputs.depth != inputs.max-depth }}
uses: actions/github-script@v6
env:
RESULTS: ${{ needs.generate-regression.outputs.results }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const results = [];
for (const item of JSON.parse(process.env.RESULTS)) {
// Check if branch exists
const branchExists = await github.rest.repos.getBranch({
owner: context.repo.owner,
repo: context.repo.repo,
branch: item.branch
})
.then(()=>true)
.catch(()=>false)
console.log(context.repo.owner);
console.log(context.repo.repo);
console.log(item.branch);
if(!branchExists) {
console.log(`Branch ${item.branch} does not exist, skipping workflow dispatch`);
continue
}
const dispatchId = Math.random().toString(36).substring(2, 15);
// Branch exists, dispatch workflow
const response = await fetch(`https://api.github.com/repos/${context.repo.owner}/${context.repo.repo}/actions/workflows/generate.yml/dispatches`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.TOKEN ?? github.token}`,
'Accept': 'application/vnd.github.v3+json'
},
body: JSON.stringify({
ref: item.branch,
inputs: {
"dispatchId": dispatchId,
"depth": "" + (${{ inputs.depth }} + 1),
"max-depth": "" + ${{ inputs.max-depth }},
"previous-file": item.filename,
"website-url": "${{ inputs.website-url }}",
"login_username": "${{ inputs.login_username }}",
"login_password": "${{ inputs.login_password }}"
}
})
});
console.log("----------------------------------")
console.log(response.status, await response.text());
console.log(`Dispatched workflow for branch: ${item.branch}`);
results.push({
...item,
dispatchId: dispatchId
});
}
require('fs').writeFileSync('results.json', JSON.stringify(results, null, 2));
- name: Upload Results
uses: actions/upload-artifact@v4
with:
name: results.json
path: results.json