Skip to content

Update plugins repository references #1069

Update plugins repository references

Update plugins repository references #1069

name: Update plugins repository references
on:
workflow_dispatch:
inputs:
regexps:
description: line-separated list of regular expressions of the plugin packages to discover. An expression surrounded by single quotes is taken as a litteral package name.
type: string
required: false
default: ""
workspace-path:
description: relative path of a workspace the discovery should be focused on
type: string
required: false
default: ""
allow-workspace-addition:
description: allow creating PRs that will add workspaces
type: boolean
required: false
release-branch-pattern:
description: A regular expression that defines active release branches. If not provided, the last 2 release branches (release-x.x) will be used.
type: string
required: false
default: ""
single-branch:
description: If provided, only the specified branch will receive updates, but the release branch pattern will still be used to find the minimum target backstage version.
type: string
required: false
default: ""
pr-to-update:
description: optional PR number of a PR to update
type: string
required: false
default: ""
verbose:
description: enable verbose logs
type: boolean
required: false
default: false
debug:
description: enable debug mode in bash scripts
type: boolean
required: false
default: false
workflow_call:
inputs:
regexps:
description: line-separated list of regular expressions of the plugin packages to discover. An expression surrounded by single quotes is taken as a litteral package name.
type: string
required: false
default: ""
workspace-path:
description: relative path of a workspace the discovery should be focused on
type: string
required: false
default: ""
pr-to-update:
type: string
required: false
default: ""
allow-workspace-addition:
description: allow creating PRs that will add workspaces
type: boolean
required: false
release-branch-pattern:
description: A regular expression that defines active release branches. If not provided, the last 2 release branches (release-x.x) will be used.
type: string
required: false
default: ""
single-branch:
description: If provided, only the specified branch will receive updates, but the release branch pattern will still be used to find the minimum target backstage version.
type: string
required: false
default: ""
verbose:
description: enable verbose logs
type: boolean
required: false
default: false
debug:
description: enable debug mode in bash scripts
type: boolean
required: false
default: false
schedule:
- cron: '0 12 * * *'
- cron: '0 19 * * *'
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ inputs.pr-to-update }}
cancel-in-progress: true
jobs:
prepare:
runs-on: ubuntu-latest
name: Prepare
outputs:
regexps: ${{ steps.read-regexps.outputs.REGEXPS }}
exclude-workspaces: ${{ steps.read-exclude-patterns.outputs.EXCLUDE_WORKSPACES }}
release-branch-pattern: ${{ steps.read-release-branch-pattern.outputs.RELEASE_BRANCH_PATTERN }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Read Regexps
id: read-regexps
env:
INPUT_REGEXPS: ${{ inputs.regexps }}
shell: bash
run: |
REGEXPS="${INPUT_REGEXPS}"
if [[ "${REGEXPS}" == "" ]]
then
REGEXPS="$(cat workspace-discovery-include)"
fi
echo "Regexps of plugins to export:"
echo "$REGEXPS"
echo "REGEXPS=$(echo $REGEXPS | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: Read Exclude Patterns
id: read-exclude-patterns
shell: bash
run: |
if [[ -f workspace-discovery-exclude ]]
then
EXCLUDE_WORKSPACES="$(grep -v '^#' workspace-discovery-exclude | grep -v '^$' | tr '\n' ' ')"
else
EXCLUDE_WORKSPACES=""
fi
echo "Workspace exclude patterns: ${EXCLUDE_WORKSPACES}"
echo "EXCLUDE_WORKSPACES=${EXCLUDE_WORKSPACES}" >> $GITHUB_OUTPUT
- name: Read Release Branch Pattern
id: read-release-branch-pattern
env:
INPUT_RELEASE_BRANCH_PATTERN: ${{ inputs.release-branch-pattern }}
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
RELEASE_BRANCH_PATTERN="${INPUT_RELEASE_BRANCH_PATTERN}"
if [[ "${RELEASE_BRANCH_PATTERN}" == "" ]]
then
# Get the last 2 release branch names, sorted by version, and build a regex like ^release-(1\.7|1\.8)$
RELEASE_BRANCH_PATTERN="$(gh api repos/${GITHUB_REPOSITORY}/branches --paginate | \
jq -r '[.[].name | select(test("^release-")) | sub("^release-";"")]
| sort_by(split(".") | map(tonumber))
| reverse
| .[:2]
| map(gsub("\\."; "\\."))
| "^release-(" + join("|") + ")$"')"
fi
echo "Release branch pattern: ${RELEASE_BRANCH_PATTERN}"
echo "RELEASE_BRANCH_PATTERN=${RELEASE_BRANCH_PATTERN}" >> $GITHUB_OUTPUT
update-branches:
name: Update Branches
needs: prepare
if: github.event_name != 'schedule'
uses: redhat-developer/rhdh-plugin-export-utils/.github/workflows/update-plugins-repo-refs.yaml@main
with:
regexps: ${{ needs.prepare.outputs.regexps }}
exclude-workspaces: ${{ needs.prepare.outputs.exclude-workspaces }}
workspace-path: ${{ inputs.workspace-path }}
pr-to-update: ${{ inputs.pr-to-update }}
overlay-repo: ${{ github.repository }}
release-branch-pattern: ${{ needs.prepare.outputs.release-branch-pattern }}
single-branch: ${{ inputs.single-branch }}
verbose: ${{ inputs.verbose != '' && inputs.verbose }}
debug: ${{ inputs.debug != '' && inputs.debug }}
allow-workspace-addition: ${{ inputs.allow-workspace-addition != '' && inputs.allow-workspace-addition }}
permissions:
contents: write
pull-requests: write
update-main-branch:
name: Update Main Branch
needs: prepare
if: >-
(github.event_name == 'schedule')
uses: redhat-developer/rhdh-plugin-export-utils/.github/workflows/update-plugins-repo-refs.yaml@main
with:
regexps: ${{ needs.prepare.outputs.regexps }}
exclude-workspaces: ${{ needs.prepare.outputs.exclude-workspaces }}
overlay-repo: ${{ github.repository }}
release-branch-pattern: ${{ needs.prepare.outputs.release-branch-pattern }}
single-branch: "main" # we want to update only the main branch
verbose: false
debug: false
allow-workspace-addition: true
permissions:
contents: write
pull-requests: write
label-prs:
name: Label PRs
needs: [update-branches, update-main-branch]
if: |
always() &&
(needs.update-branches.result != 'skipped' ||
needs.update-main-branch.result != 'skipped')
uses: ./.github/workflows/label-mandatory-workspace-prs.yaml
permissions:
contents: read
pull-requests: write
issues: read
collect-auto-publish-prs:
name: Collect PRs for auto-publish
needs: [update-branches, update-main-branch]
if: |
!cancelled() &&
(needs.update-branches.result == 'success' ||
needs.update-main-branch.result == 'success')
runs-on: ubuntu-latest
outputs:
pr-numbers: ${{ steps.collect.outputs.pr-numbers }}
steps:
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
id: collect
with:
script: |
const run = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
});
const runStart = new Date(run.data.run_started_at);
const prs = await github.paginate(github.rest.pulls.list, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'updated',
direction: 'desc',
});
const recentPrs = prs.filter(pr =>
pr.head.ref.startsWith('workspaces/') &&
new Date(pr.updated_at) >= runStart
);
const numbers = recentPrs.map(pr => pr.number);
core.setOutput('pr-numbers', JSON.stringify(numbers));
core.info(`Found ${numbers.length} PRs for auto-publish: ${numbers}`);
auto-publish:
name: Auto-publish PRs
needs: collect-auto-publish-prs
if: |
!cancelled() &&
needs.collect-auto-publish-prs.result == 'success' &&
needs.collect-auto-publish-prs.outputs.pr-numbers != '[]'
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Trigger PR Actions publish for each updated PR
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
INPUT_PR_NUMBERS: ${{ needs.collect-auto-publish-prs.outputs.pr-numbers }}
with:
script: |
const prNumbers = JSON.parse(core.getInput('pr_numbers'));
for (const prNumber of prNumbers) {
core.info(`Triggering publish for PR #${prNumber}`);
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'pr-actions.yaml',
ref: '${{ github.ref_name }}',
inputs: {
'pr-number': String(prNumber),
'command-name': 'publish',
},
});
await new Promise(r => setTimeout(r, 2000));
}