|
| 1 | +name: build_rename |
| 2 | + |
| 3 | +# Renames all artifacts to a chosen namespace and pushes the result to |
| 4 | +# the branch rename_<name>, e.g. rename_zmyui5 - ready to pull with |
| 5 | +# abapGit for a parallel installation in the same SAP system. The |
| 6 | +# renaming itself is the plain abaplint rename with the checked-in |
| 7 | +# config .github/abaplint/rename.json (placeholder "zabap2ui5"); this |
| 8 | +# workflow only sets the chosen name in the config and stores the |
| 9 | +# result. Re-running with the same name updates the branch to the |
| 10 | +# current main state; without content changes nothing is pushed. The |
| 11 | +# main commit is carried as second parent so GitHub shows the branch as |
| 12 | +# "ahead" instead of "behind" main. |
| 13 | + |
| 14 | +on: |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + namespace: |
| 18 | + description: "New namespace (max. 9 characters), e.g. ZMYUI5" |
| 19 | + required: true |
| 20 | + type: string |
| 21 | + default: zabap2ui5 |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: write |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: build_rename-${{ inputs.namespace }} |
| 28 | + cancel-in-progress: false |
| 29 | + |
| 30 | +jobs: |
| 31 | + build_rename: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + timeout-minutes: 15 |
| 34 | + env: |
| 35 | + NAMESPACE: ${{ inputs.namespace }} |
| 36 | + steps: |
| 37 | + # validate the input and derive the branch name before building |
| 38 | + - name: Derive branch name |
| 39 | + run: | |
| 40 | + if ! printf '%s' "$NAMESPACE" | grep -Eq '^[A-Za-z][A-Za-z0-9_]{0,8}$'; then |
| 41 | + echo "::error::Invalid namespace '$NAMESPACE' (letter + letters/digits/underscore, max. 9 characters)" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + ns=$(printf '%s' "$NAMESPACE" | tr '[:upper:]' '[:lower:]') |
| 45 | + if [ "$ns" = "z2ui5" ]; then |
| 46 | + echo "::error::Namespace '$NAMESPACE' is the original namespace - nothing to rename" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + echo "NS=$ns" >> "$GITHUB_ENV" |
| 50 | + echo "BRANCH=rename_$ns" >> "$GITHUB_ENV" |
| 51 | + echo "Building branch: rename_$ns" |
| 52 | +
|
| 53 | + - uses: actions/checkout@v5 |
| 54 | + - uses: actions/setup-node@v5 |
| 55 | + with: |
| 56 | + node-version: '22' |
| 57 | + cache: 'npm' |
| 58 | + - run: npm ci |
| 59 | + |
| 60 | + # set the chosen name in the rename config and run the abaplint |
| 61 | + # rename; it writes the renamed sources to |
| 62 | + # .github/abaplint/output/<workspace path>/src |
| 63 | + - name: Rename to ${{ inputs.namespace }} |
| 64 | + run: | |
| 65 | + sed "s/zabap2ui5/$NS/g" .github/abaplint/rename.json > .github/abaplint/rename_run.json |
| 66 | + npx abaplint .github/abaplint/rename_run.json --rename |
| 67 | +
|
| 68 | + # branch content: the renamed src tree plus the abapGit descriptor |
| 69 | + # and the license |
| 70 | + - name: Assemble branch content |
| 71 | + run: | |
| 72 | + src=$(find .github/abaplint/output -type d -name src | head -n 1) |
| 73 | + if [ -z "$src" ]; then |
| 74 | + echo "::error::no renamed src folder found under .github/abaplint/output" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | + out=".github/out/$BRANCH" |
| 78 | + rm -rf "$out" |
| 79 | + mkdir -p "$out" |
| 80 | + cp -r "$src" "$out/src" |
| 81 | + cp LICENSE "$out/" |
| 82 | + cp .abapgit.xml "$out/" |
| 83 | +
|
| 84 | + - name: Push renamed branch |
| 85 | + run: | |
| 86 | + b="$BRANCH" |
| 87 | + git config user.name 'github-actions[bot]' |
| 88 | + git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 89 | + git fetch origin "$b" --depth 1 2>/dev/null || true |
| 90 | + parent=$(git rev-parse -q --verify "refs/remotes/origin/$b" || true) |
| 91 | + index="$RUNNER_TEMP/index-$b" |
| 92 | + rm -f "$index" |
| 93 | + (cd ".github/out/$b" && GIT_DIR="$GITHUB_WORKSPACE/.git" GIT_WORK_TREE=. GIT_INDEX_FILE="$index" git add -A) |
| 94 | + tree=$(GIT_INDEX_FILE="$index" git write-tree) |
| 95 | + if [ -n "$parent" ] && [ "$(git rev-parse "$parent^{tree}")" = "$tree" ]; then |
| 96 | + echo "$b: no changes" |
| 97 | + exit 0 |
| 98 | + fi |
| 99 | + commit=$(git commit-tree "$tree" ${parent:+-p "$parent"} -p "$GITHUB_SHA" -m "build: $b from $GITHUB_SHA") |
| 100 | + git push origin "$commit:refs/heads/$b" |
| 101 | + echo "$b: pushed $commit" |
0 commit comments