CI :: OSL :: Export Dist to osl-images #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "CI :: OSL :: Export Dist to osl-images" | |
| on: | |
| workflow_dispatch: | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
| PNPM_FILTER: ${{ vars.OSL_IMAGES_PNPM_FILTER }} | |
| OSL_PACKAGES: ${{ vars.OSL_IMAGES_PACKAGES }} | |
| jobs: | |
| export_dist: | |
| runs-on: ubuntu-latest | |
| if: ${{ vars.ENABLE_OSL_DIST_EXPORT == 'yes' }} | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout Source Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| - name: Setup Git Environment | |
| run: | | |
| git config --global user.name "domhanak" | |
| git config --global user.email "dhanak@redhat.com" | |
| - name: Setup Environment | |
| uses: ./.github/actions/setup-env | |
| - name: Setup Environment Variables | |
| run: bash ./.github/supporting-files/ci/osl/export_vars.sh | |
| shell: bash | |
| - name: Get Kiegroup git ref urls | |
| id: get_kiegroup_git_refs | |
| run: | | |
| # Get Kiegroup Drools Git Ref | |
| DROOLS_GIT_REF=$(git ls-remote "${{ env.DROOLS_AND_KOGITO__droolsRepoUrl}}" refs/heads/main | awk '{print $1}') | |
| echo "DROOLS_AND_KOGITO__droolsRepoUrl=$DROOLS_GIT_REF" >> "$GITHUB_OUTPUT" | |
| Get Kiegroup Runtimes Git Ref | |
| RUNTIMES_GIT_REF=$(git ls-remote "${{ env.DROOLS_AND_KOGITO__kogitoRuntimesRepoUrl}}" refs/heads/main | awk '{print $1}') | |
| echo "DROOLS_AND_KOGITO__kogitoRuntimesRepoGitRef=$RUNTIMES_GIT_REF" >> "$GITHUB_OUTPUT" | |
| # Get Kiegroup Apps Git Ref | |
| APPS_GIT_REF=$(git ls-remote "${{ env.DROOLS_AND_KOGITO__kogitoAppsRepoUrl}}" refs/heads/main | awk '{print $1}') | |
| echo "DROOLS_AND_KOGITO__kogitoAppsRepoGitRef=$APPS_GIT_REF" >> "$GITHUB_OUTPUT" | |
| - name: Run pnpm bootstrap | |
| run: eval "pnpm bootstrap ${{ env.OSL_IMAGES_PNPM_FILTER }} --no-frozen-lockfile" | |
| env: | |
| DROOLS_AND_KOGITO__droolsRepoUrl: "${{ steps.get_kiegroup_git_refs.outputs.DROOLS_AND_KOGITO__droolsRepoUrl}}" | |
| DROOLS_AND_KOGITO__kogitoRuntimesRepoGitRef: "${{ steps.get_kiegroup_git_refs.outputs.DROOLS_AND_KOGITO__kogitoRuntimesRepoGitRef}}" | |
| DROOLS_AND_KOGITO__kogitoAppsRepoGitRef: "${{ steps.get_kiegroup_git_refs.outputs.DROOLS_AND_KOGITO__kogitoAppsRepoGitRef}}" | |
| shell: bash | |
| - name: Build OSL Packages | |
| run: eval "pnpm ${{ env.OSL_IMAGES_PNPM_FILTER }} --workspace-concurrency=1 build:prod" | |
| env: | |
| NODE_OPTIONS: "--max_old_space_size=4096" | |
| shell: bash | |
| - name: Checkout Target Repo (osl-images) | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: kubesmarts/osl-images | |
| token: ${{ secrets.GH_TOKEN }} | |
| path: target-repo | |
| - name: Consolidate Dist Outputs to Target Repo | |
| run: | | |
| set -euo pipefail | |
| BASE="target-repo/images-dist" | |
| mkdir -p "$BASE/modules" "$BASE/scripts" | |
| for pkg in ${{ env.OSL_PACKAGES }}; do | |
| SRC="packages/${pkg}/dist" | |
| echo "π¨ Processing dist for $pkg" | |
| if [ ! -d "$SRC" ]; then | |
| echo "β οΈ $SRC not found, skipping." | |
| continue | |
| fi | |
| # ββ Merge modules βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| if [ -d "$SRC/modules" ]; then | |
| cp -r "$SRC/modules/"* "$BASE/modules/" | |
| fi | |
| # ββ Merge scripts βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| if [ -d "$SRC/scripts" ]; then | |
| cp -r "$SRC/scripts/"* "$BASE/scripts/" | |
| fi | |
| # ββ Copy package YAMLs ββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| for yf in "$SRC"/*.yaml; do | |
| fname="$(basename "$yf")" | |
| case "$fname" in | |
| content-sets.yaml) | |
| # only copy the first one | |
| if [ ! -f "$BASE/content-sets.yaml" ]; then | |
| cp "$yf" "$BASE/" | |
| fi | |
| ;; | |
| *) | |
| # this will copy image.yaml (or any other yaml) for each pkg | |
| cp "$yf" "$BASE/" | |
| ;; | |
| esac | |
| done | |
| # ββ Skip tests/ and Makefile βββββββββββββββββββββββββββββββββββββββββββ | |
| # (We never copied them, so nothing to remove.) | |
| done | |
| shell: bash | |
| - name: Commit and Push to Target Repo | |
| run: | | |
| set -euo pipefail | |
| cd target-repo | |
| BRANCH="export-dist-$(date +'%Y%m%d-%H%M%S')" | |
| git checkout -b "$BRANCH" | |
| git add . | |
| git commit -m "chore: export OSL dist from main" | |
| git push -u origin "$BRANCH" | |
| echo "EXPORT_BRANCH=$BRANCH" >> $GITHUB_ENV | |
| shell: bash | |
| - name: Create Pull Request | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| SYNC_REVIEWERS: ${{ vars.SYNC_REVIEWERS }} | |
| run: | | |
| set -euo pipefail | |
| PR_TITLE="[$(date +'%Y-%m-%d:%H%M%S')] - :robot: Export OSL dist from main" | |
| REVIEWERS_OPTION="" | |
| if [[ -n "$SYNC_REVIEWERS" ]]; then | |
| REVIEWERS_OPTION="--reviewer $SYNC_REVIEWERS" | |
| fi | |
| PR_URL=$(gh pr create \ | |
| --repo kubesmarts/osl-images \ | |
| --title "$PR_TITLE" \ | |
| --body "This PR includes the latest dist output for packages: $OSL_PACKAGES" \ | |
| --base main \ | |
| --head "$EXPORT_BRANCH" $REVIEWERS_OPTION) | |
| echo "β Created PR: $PR_URL" | |
| shell: bash |