Skip to content

added setup

added setup #25

Workflow file for this run

name: Main Workflow

Check failure on line 1 in .github/workflows/generate.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/generate.yml

Invalid workflow file

you may only define up to 10 `inputs` for a `workflow_dispatch` event
permissions:
actions: write
contents: write
statuses: write
pull-requests: write
on:
workflow_dispatch:
inputs:
primaryId:
type: string
required: true
description: Primary Run ID to carry through layers
dispatchId:
type: string
depth:
type: number
default: 1
breadth:
type: number
default: 2
max-depth:
type: number
default: 1
prerun:
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
app-type:
type: string
description: Type of app, desktop or web
setup-instructions:
type: string
description: "Extra Setup"
workflow_call:
inputs:
primaryId:
type: string
required: true
description: Primary Run ID to carry through layers
dispatchId:
type: string
depth:
type: number
default: 1
breadth:
type: number
default: 2
max-depth:
type: number
default: 1
prerun:
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
app-type:
type: string
description: Type of app, desktop or web
secrets:
TESTDRIVER_API_KEY:
required: true
GH_TOKEN:
required: true
jobs:
match-dispatchId:
if: ${{ inputs.dispatchId }}
runs-on: [ubuntu-latest]
outputs:
setup: ${{ steps.setup.outputs.result }}
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 }}"
- uses: 'actions/github-script@v6'
id: setup
env:
LOGIN_USERNAME: ${{ inputs.login_username }}
LOGIN_PASSWORD: ${{ inputs.login_password }}
SETUP_INSTRUCTIONS: ${{ inputs.setup-instructions }}
with:
script: |
let instructions = [];
const username = process.env.LOGIN_USERNAME;
const password = process.env.LOGIN_PASSWORD;
const setup = process.env.SETUP_INSTRUCTIONS;
if (username && password) {
instructions.push(`login with username ${ username }} and password ${ login_password }`)
}
if (setup) {
instructions = [...instructions, ...setup.split(";")];
}
if (instructions.length) {
instructions.push("/save prerun.yml");
}
return JSON.stringify(instructions);
generate-exploratory:
needs: match-dispatchId
uses: ./.github/workflows/generate-exploratory.yml
with:
primaryId: ${{ inputs.primaryId }}
depth: ${{ fromJson(inputs.depth) }}
breadth: ${{ fromJson(inputs.breadth) }}
max-depth: ${{ fromJson(inputs.max-depth) }}
base-branch: ${{ github.ref_name }}
previous-file: ${{ inputs.previous-file }}
prerun: ${{ inputs.prerun }}
app-type: ${{ inputs.app-type }}
setup-instructions: $${{ needs.outputs.setup }}
secrets:
TESTDRIVER_API_KEY: ${{ secrets.TESTDRIVER_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
generate-regression:
needs: generate-exploratory
uses: ./.github/workflows/generate-regressions.yml
with:
primaryId: ${{ inputs.primaryId }}
depth: ${{ fromJson(inputs.depth) }}
max-depth: ${{ fromJson(inputs.max-depth) }}
base-branch: ${{ needs.generate-exploratory.outputs.pr-branch }}
prerun: ${{ inputs.prerun }}
secrets:
TESTDRIVER_API_KEY: ${{ secrets.TESTDRIVER_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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)
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,
"primaryId": "${{ inputs.primaryId }}",
"depth": "" + (${{ inputs.depth }} + 1),
"max-depth": "" + ${{ inputs.max-depth }},
"previous-file": item.filename,
"prerun": ${{ toJson(inputs.prerun) }},
"login_username": "${{ inputs.login_username }}",
"login_password": "${{ inputs.login_password }}",
"app-type": "${{ inputs.app-type }}"
}
})
});
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