diff --git a/.github/workflows/export-dynamic.yaml b/.github/workflows/export-dynamic.yaml index 25d7ebdb..a89058d8 100644 --- a/.github/workflows/export-dynamic.yaml +++ b/.github/workflows/export-dynamic.yaml @@ -128,6 +128,16 @@ on: description: Optional commit ID of the last successful publishing of plugin container images type: string required: false + + prepare-downstream-sources: + description: > + When true, after a successful plugin export run the prepare-sources CLI + (prepare-rhdh-supported-sources) to transform the workspace into a + prepared downstream source tree. Default false leaves existing export + behavior unchanged. + type: boolean + default: false + required: false outputs: published-exports: @@ -356,6 +366,52 @@ jobs: retention-days: ${{ inputs.artifact-retention-days }} overwrite: true + # RHIDP-15846: optional post-export prepare-sources pipeline. + # workspace-path uses plugins-root (. = flat repo; workspaces/ = non-flat). + # overlay-path is the checked-out overlay workspace directory (source.json). + # Until construct-artifact (RHIDP-15845) lands, upload the prepared tree as a + # workflow artifact instead of pushing an OCI image. + - name: Resolve prepared sources paths + if: ${{ inputs.prepare-downstream-sources && success() && steps.export-dynamic.outputs.failed-exports == '' && steps.export-dynamic.outputs.workspace-skipped-unchanged-since == 'false' }} + id: prepare-paths + env: + PLUGINS_ROOT: ${{ inputs.plugins-root }} + OVERLAY_ROOT: ${{ inputs.overlay-root }} + run: | + # Flat repos use plugins-root "."; upload-artifact rejects paths ending in "/." + if [[ "${PLUGINS_ROOT}" == "." || -z "${PLUGINS_ROOT}" ]]; then + echo "workspace_path=${GITHUB_WORKSPACE}/source-repo" >> "$GITHUB_OUTPUT" + else + echo "workspace_path=${GITHUB_WORKSPACE}/source-repo/${PLUGINS_ROOT}" >> "$GITHUB_OUTPUT" + fi + echo "overlay_path=${GITHUB_WORKSPACE}/overlay-repo/${OVERLAY_ROOT}" >> "$GITHUB_OUTPUT" + + # $/ = self repository reference: resolves to this workflow file's repository + # at the running commit, even when called from the overlays repo. No checkout + # step needed, and the reference is commit-locked by definition. + - name: Prepare downstream sources + if: ${{ inputs.prepare-downstream-sources && success() && steps.export-dynamic.outputs.failed-exports == '' && steps.export-dynamic.outputs.workspace-skipped-unchanged-since == 'false' }} + id: prepare-downstream-sources + uses: $/prepare-sources + with: + workspace-path: ${{ steps.prepare-paths.outputs.workspace_path }} + overlay-path: ${{ steps.prepare-paths.outputs.overlay_path }} + + - name: Upload prepared downstream sources + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 + if: ${{ inputs.prepare-downstream-sources && success() && steps.prepare-downstream-sources.outcome == 'success' }} + with: + name: prepared downstream sources${{ steps.set-artifacts-name-suffix.outputs.ARTIFACTS_NAME_SUFFIX }} + path: | + ${{ steps.prepare-paths.outputs.workspace_path }} + !**/node_modules + !**/.yarn/cache + !**/.git + if-no-files-found: warn + retention-days: ${{ inputs.artifact-retention-days }} + overwrite: true + include-hidden-files: true + - name: Upload the project to workflow artifacts on failure uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 if: ${{ inputs.upload-project-on-error && (failure() || steps.export-dynamic.outputs.failed-exports) }} diff --git a/.github/workflows/export-workspaces-as-dynamic.yaml b/.github/workflows/export-workspaces-as-dynamic.yaml index 5aa1dc99..0b0548ea 100644 --- a/.github/workflows/export-workspaces-as-dynamic.yaml +++ b/.github/workflows/export-workspaces-as-dynamic.yaml @@ -74,6 +74,15 @@ on: type: string required: false + prepare-downstream-sources: + description: > + When true, after a successful plugin export run the prepare-sources CLI + to transform each workspace into a prepared downstream source tree. + Default false leaves existing export behavior unchanged. + type: boolean + default: false + required: false + outputs: published-exports: value: '${{ jobs.export.outputs.published-exports }}' @@ -264,7 +273,12 @@ jobs: export: name: Export ${{ matrix.workspace.overlay-root }} needs: prepare - uses: redhat-developer/rhdh-plugin-export-utils/.github/workflows/export-dynamic.yaml@main + # Same-repo, same-commit as this workflow. Prefer "$/" over "./" — when overlays + # call this reusable workflow, nested "./" can resolve against the top-level + # caller (overlays) instead of utils. "$/" keeps export-dynamic in lockstep so + # new inputs (prepare-downstream-sources) are not dropped by pinning @main. + # https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows + uses: $/.github/workflows/export-dynamic.yaml strategy: fail-fast: false matrix: @@ -289,6 +303,7 @@ jobs: target-backstage-version: ${{ needs.prepare.outputs.backstage-version }} last-publish-commit: ${{ inputs.last-publish-commit }} image-registry-user: ${{ inputs.image-registry-user }} + prepare-downstream-sources: ${{ inputs.prepare-downstream-sources }} secrets: image-registry-password: ${{ secrets.image-registry-password }} diff --git a/.github/workflows/test-prepare-downstream-sources.yaml b/.github/workflows/test-prepare-downstream-sources.yaml new file mode 100644 index 00000000..0d8fc94a --- /dev/null +++ b/.github/workflows/test-prepare-downstream-sources.yaml @@ -0,0 +1,35 @@ +# Temporary RHIDP-15846 test harness — remove after AC sign-off. +# Calls the same-repo reusable export workflow (fork→fork reusable calls startup-fail). +name: Test Prepare Downstream Sources Export +on: + workflow_dispatch: + inputs: + workspace-path: + description: Overlay workspace path (e.g. workspaces/topology or workspaces/backstage) + type: string + required: true + default: workspaces/topology + prepare-downstream-sources: + description: Exercise prepare-sources post-export steps + type: boolean + required: false + default: true + +jobs: + export: + uses: ./.github/workflows/export-workspaces-as-dynamic.yaml + with: + workspace-path: ${{ inputs.workspace-path }} + overlay-repo: redhat-developer/rhdh-plugin-export-overlays + overlay-branch: main + publish-container: false + upload-project-on-error: true + prepare-downstream-sources: ${{ inputs.prepare-downstream-sources }} + image-registry-user: ${{ github.actor }} + secrets: + image-registry-password: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + packages: write + attestations: write + id-token: write diff --git a/prepare-sources/action.yaml b/prepare-sources/action.yaml index 0f3a3200..83d0d9a2 100644 --- a/prepare-sources/action.yaml +++ b/prepare-sources/action.yaml @@ -17,7 +17,9 @@ runs: uses: voidzero-dev/setup-vp@3754dd7dbdb32bd8f6d28b6043de13ad3a75f21f # v1.21.1 with: working-directory: ${{ github.action_path }} - cache: true + cache: false + # cache:true fails hashing package-lock.json when this action is fetched + # under _actions/ (composite reuse from export-dynamic). Install still runs. run-install: | args: ['--prod']