Skip to content

Test: trigger updateTestConfig workflow #1

Test: trigger updateTestConfig workflow

Test: trigger updateTestConfig workflow #1

Workflow file for this run

name: Pull Request Actions
on:
issue_comment:
types: [created, edited]
jobs:
prepare:
runs-on: ubuntu-latest
name: Prepare
concurrency:
group: prepare-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: false
if: github.event.issue.pull_request && (github.event.comment.body == '/publish' || github.event.comment.body == '/update-versions' || github.event.comment.body == '/update-commit')
outputs:
target-branch: ${{ steps.get-branch.outputs.target-branch }}
overlay-branch: ${{ steps.get-branch.outputs.overlay-branch }}
overlay-repo: ${{ steps.get-branch.outputs.overlay-repo }}
overlay-commit: ${{ steps.get-branch.outputs.overlay-commit }}
workspace: ${{ steps.get-branch.outputs.workspace }}
pr-number: ${{ steps.get-branch.outputs.pr-number }}
permissions:
statuses: write
steps:
- name: Get PR branch data
id: get-branch
uses: actions/github-script@v7
with:
script: |
const currentPullRequest = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const targetBranch = currentPullRequest.data.base.ref;
core.setOutput('target-branch', targetBranch);
const prBranch = currentPullRequest.data.head.ref;
core.setOutput('overlay-branch', prBranch);
const prRepo = currentPullRequest.data.head.repo.full_name;
core.setOutput('overlay-repo', prRepo);
const prNumber = currentPullRequest.data.number;
core.setOutput('pr-number', prNumber);
const prCommit = currentPullRequest.data.head.sha;
core.setOutput('overlay-commit', prCommit);
let workspace = '';
const matches = prBranch.match(/^workspaces\/release-.+__(.+)$/);
if (matches && matches.length == 2) {
workspace = `workspaces/${matches[1]}`;
} else {
const prFiles = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const workspaces = [ ... new Set(prFiles.data
.map(f => f.filename.match(/^workspaces\/([^\/]+)\/.*/))
.filter(match => match)
.map(match => match[1])
)];
if (workspaces.length === 1) {
workspace =`workspaces/${workspaces[0]}`;
}
}
core.setOutput('workspace', workspace);
if (workspace === '') {
return;
}
const workflowRun = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: '${{ github.run_id }}',
});
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: prCommit,
description: '${{ github.workflow }}',
state: 'pending',
target_url: workflowRun.data.html_url,
context: context.payload.comment.body.substring(1)
});
export:
name: Publish PR Dynamic Plugin Images
needs:
- prepare
- checkPRUpToDate
concurrency:
group: export-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: true
if: github.event.comment.body == '/publish' && needs.prepare.outputs.overlay-branch != '' && needs.prepare.outputs.workspace != ''
uses: redhat-developer/rhdh-plugin-export-utils/.github/workflows/export-workspaces-as-dynamic.yaml@main
with:
overlay-branch: ${{ needs.prepare.outputs.overlay-branch }}
overlay-repo: ${{ needs.prepare.outputs.overlay-repo }}
workspace-path: ${{ needs.prepare.outputs.workspace }}
publish-container: true
image-repository-prefix: ${{ format('ghcr.io/{0}', github.repository) }}
image-tag-prefix: ${{ format('pr_{0}__', needs.prepare.outputs.pr-number) }}
secrets:
image-registry-user: ${{ github.actor }}
image-registry-password: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
attestations: write
packages: write
id-token: write
updateTestConfig:
runs-on: ubuntu-latest
name: Update Test Config with Published OCI References
needs:
- prepare
- export
concurrency:
group: updateTestConfig-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: true
if: github.event.comment.body == '/publish' && needs.prepare.outputs.overlay-branch != '' && needs.prepare.outputs.workspace != '' && needs.export.outputs.published-exports != ''
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.overlay-branch }}
repository: ${{ needs.prepare.outputs.overlay-repo }}
- name: Update dynamic-plugins.test.yaml
env:
PUBLISHED_EXPORTS: ${{ needs.export.outputs.published-exports }}
PR_NUMBER: ${{ needs.prepare.outputs.pr-number }}
WORKSPACE: ${{ needs.prepare.outputs.workspace }}
run: |
# Parse the published exports to get the OCI image reference
echo "Published exports: $PUBLISHED_EXPORTS"
# Extract plugin name and version from the published exports
# Format is expected to be like: ghcr.io/<repo>:pr_<PR#>__<plugin_version>
for export in $PUBLISHED_EXPORTS; do
if [[ "$export" =~ ghcr\.io/([^:]+):pr_${PR_NUMBER}__(.+) ]]; then
IMAGE_REPO="${BASH_REMATCH[1]}"
PLUGIN_VERSION="${BASH_REMATCH[2]}"
# Get plugin name from workspace path
PLUGIN_NAME=$(basename "$WORKSPACE")
# Construct the OCI reference
OCI_REF="oci://ghcr.io/${IMAGE_REPO}:pr_${PR_NUMBER}__${PLUGIN_VERSION}!backstage-community-plugin-${PLUGIN_NAME}"
# Update the test file if it exists
TEST_FILE="${WORKSPACE}/tests/dynamic-plugins.test.yaml"
if [ -f "$TEST_FILE" ]; then
echo "Updating $TEST_FILE with OCI reference: $OCI_REF"
sed -i "s|package: oci://.*|package: ${OCI_REF}|" "$TEST_FILE"
fi
fi
done
- name: Commit and push changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git diff --staged --quiet || git commit -m "Update test config with PR OCI references"
git push
checkBackstageCompatibility:
name: Check workspace backstage compatibility
needs:
- prepare
concurrency:
group: checkBackstageCompatibility-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: true
if: github.event.comment.body == '/publish' && needs.prepare.outputs.overlay-branch != '' && needs.prepare.outputs.workspace != ''
uses: redhat-developer/rhdh-plugin-export-utils/.github/workflows/check-backstage-compatibility.yaml@main
with:
overlay-branch: ${{ needs.prepare.outputs.overlay-branch }}
overlay-repo: ${{ needs.prepare.outputs.overlay-repo }}
workspace-path: ${{ needs.prepare.outputs.workspace }}
add_publish_completion_comment:
needs:
- prepare
- checkPRUpToDate
- export
- updateTestConfig
- checkBackstageCompatibility
concurrency:
group: add_publish_completion_comment-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: false
permissions:
statuses: write
pull-requests: write
if: always() && github.event.comment.body == '/publish' && needs.prepare.outputs.overlay-branch != '' && needs.prepare.outputs.workspace != ''
runs-on: ubuntu-latest
steps:
- name: Add completion comment
uses: actions/github-script@v7
env:
INPUT_OVERLAY_COMMIT: ${{ needs.prepare.outputs.overlay-commit }}
INPUT_PUBLISHED_EXPORTS: ${{ needs.export.outputs.published-exports }}
INPUT_FAILED_EXPORTS: ${{ needs.export.outputs.failed-exports }}
with:
script: |
const workflowRun = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: '${{ github.run_id }}'
});
const jobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: '${{ github.run_id }}',
filter: 'latest',
});
const success = jobs.data.jobs
.filter(j => j.name.startsWith('Publish') || j.name.startsWith('export') || j.name.startsWith('Export') || j.name.startsWith('Check') || j.name.startsWith('Update Test Config'))
.every(j => j.conclusion === 'success');
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: core.getInput('overlay_commit'),
description: '${{ github.workflow }}',
state: success ? 'success' : 'failure',
target_url: workflowRun.data.html_url,
context: context.payload.comment.body.substring(1),
});
let body = `[Publish workflow](${workflowRun.data.html_url}) has completed with ${ success ? 'success' : 'failure' }.`;
const publishedExports = core.getMultilineInput('published_exports');
if (publishedExports.length > 0) {
body = `${body}\n- Published container images:`;
publishedExports.forEach(line => {
body = `${body}\n - ${line}`;
});
}
const failedExports = core.getMultilineInput('failed_exports');
if (failedExports.length > 0) {
body = `${body}\n- Plugins failed during export or container image publishing:`;
failedExports.forEach(line => {
body = `${body}\n - ${line}`;
});
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
add_no_workspace_comment:
needs:
- prepare
concurrency:
group: add_no_workspace_comment-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: false
permissions:
statuses: write
pull-requests: write
if: always() && needs.prepare.outputs.overlay-branch != '' && needs.prepare.outputs.workspace == ''
runs-on: ubuntu-latest
steps:
- name: Add success comment
uses: actions/github-script@v7
env:
INPUT_OVERLAY_COMMIT: ${{ needs.prepare.outputs.overlay-commit }}
with:
script: |
const workflowRun = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: '${{ github.run_id }}'
});
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: core.getInput('overlay_commit'),
description: '${{ github.workflow }}',
state: 'success',
target_url: workflowRun.data.html_url,
context: context.payload.comment.body.substring(1),
});
const body = `[PR action (\`${context.payload.comment.body}\`)](${workflowRun.data.html_url}) cancelled: PR doesn't touch only 1 workspace.`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
checkPRUpToDate:
name: Checks whether the PR is up-to-date with versions.json
needs:
- prepare
concurrency:
group: checkPRUpToDate-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: false
permissions:
statuses: write
pull-requests: write
if: always() && github.event.comment.body == '/publish' && needs.prepare.outputs.overlay-branch != '' && needs.prepare.outputs.workspace != ''
runs-on: ubuntu-latest
steps:
- name: Add update check comment
uses: actions/github-script@v7
env:
INPUT_TARGET_BRANCH: ${{ needs.prepare.outputs.target-branch }}
INPUT_OVERLAY_BRANCH: ${{ needs.prepare.outputs.overlay-branch }}
INPUT_OVERLAY_REPO: ${{ needs.prepare.outputs.overlay-repo }}
with:
script: |
const path = 'versions.json';
const releaseBranch = core.getInput('target_branch');
if (! releaseBranch?.startsWith('release-') && ! releaseBranch?.startsWith('main') ) {
core.notice(`Current PR is not based on a release branch.`);
return;
}
const { data: sourceFile } = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path,
ref: releaseBranch,
});
if (!('type' in sourceFile) || sourceFile.type !== 'file') {
core.setFailed(`\`${path}\` is not a file on branch \`${releaseBranch}\``);
return;
}
const sourceContent = Buffer.from(
sourceFile.content,
(Buffer.isEncoding(sourceFile.encoding) ? sourceFile.encoding : 'utf-8')
).toString('utf-8');
const prRepository = core.getInput('overlay_repo');
const prBranch = core.getInput('overlay_branch');
const owner = prRepository.split('/')[0];
const repo = prRepository.split('/')[1];
const { data: targetFile } = await github.rest.repos.getContent({
owner,
repo,
path,
ref: prBranch,
});
if (!('type' in targetFile) || targetFile.type !== 'file') {
core.warning(`\`${path}\` is not a file on branch ${prBranch}`);
return;
}
const targetContent = Buffer.from(
targetFile.content,
(Buffer.isEncoding(targetFile.encoding) ? targetFile.encoding : 'utf-8')
).toString('utf-8');
if (sourceContent !== targetContent) {
core.setFailed(`PR not up-to-date with the release branch`);
const body = `The \`versions.json\` file in your PR doesn't match the one in release branch #${prBranch}\nTry updating it by adding the \`/update-versions\` PR comment.`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
}
updatePRWithVersions:
name: Update versions on PR from release branch
needs:
- prepare
concurrency:
group: updatePRWithVersions-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: true
if: github.event.comment.body == '/update-versions'
uses: ./.github/workflows/update-prs-with-release-branch-commits.yaml
with:
force: true
pr: ${{ github.event.issue.number }}
release-branch: ${{ needs.prepare.outputs.target-branch }}
permissions:
contents: write
pull-requests: write
add_update_versions_completion_comment:
needs:
- prepare
- updatePRWithVersions
concurrency:
group: add_update_versions_completion_comment-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: false
permissions:
statuses: write
pull-requests: write
if: always() && github.event.comment.body == '/update-versions' && needs.prepare.outputs.overlay-branch != '' && needs.prepare.outputs.workspace != ''
runs-on: ubuntu-latest
steps:
- name: Add completion comment
uses: actions/github-script@v7
env:
INPUT_OVERLAY_COMMIT: ${{ needs.prepare.outputs.overlay-commit }}
with:
script: |
const workflowRun = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: '${{ github.run_id }}'
});
const jobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: '${{ github.run_id }}',
filter: 'latest',
});
const success = jobs.data.jobs
.filter(j => j.name.startsWith('Update versions on PR'))
.every(j => j.conclusion === 'success');
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: core.getInput('overlay_commit'),
description: '${{ github.workflow }}',
state: success ? 'success' : 'failure',
target_url: workflowRun.data.html_url,
context: context.payload.comment.body.substring(1),
});
let body = `[Update Versions workflow](${workflowRun.data.html_url}) has completed with ${ success ? 'success' : 'failure' }.`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
updatePRWithCommit:
name: Update commit on PR from automatic discovery
needs:
- prepare
concurrency:
group: updatePRWithCommit-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: true
if: github.event.comment.body == '/update-commit'
uses: ./.github/workflows/update-plugins-repo-refs.yaml
with:
release-branch-pattern: ${{ needs.prepare.outputs.target-branch }}
allow-workspace-addition: false
pr-to-update: ${{ needs.prepare.outputs.pr-number }}
workspace-path: ${{ needs.prepare.outputs.workspace }}
permissions:
contents: write
pull-requests: write
add_update_commit_completion_comment:
needs:
- prepare
- updatePRWithCommit
concurrency:
group: add_update_commit_completion_comment-${{ github.ref_name }}-${{ github.event.issue.number }}
cancel-in-progress: false
permissions:
statuses: write
pull-requests: write
if: always() && github.event.comment.body == '/update-commit' && needs.prepare.outputs.overlay-branch != '' && needs.prepare.outputs.workspace != ''
runs-on: ubuntu-latest
steps:
- name: Add completion comment
uses: actions/github-script@v7
env:
INPUT_OVERLAY_COMMIT: ${{ needs.prepare.outputs.overlay-commit }}
with:
script: |
const workflowRun = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: '${{ github.run_id }}'
});
const jobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: '${{ github.run_id }}',
filter: 'latest',
});
const success = jobs.data.jobs
.filter(j => j.name.startsWith('Update commit on PR'))
.every(j => j.conclusion === 'success' || j.conclusion === 'skipped');
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: core.getInput('overlay_commit'),
description: '${{ github.workflow }}',
state: success ? 'success' : 'failure',
target_url: workflowRun.data.html_url,
context: context.payload.comment.body.substring(1),
});
let body = `[Update Commit workflow](${workflowRun.data.html_url}) has completed with ${ success ? 'success' : 'failure' }.`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})