From 81937e4caa56f36851990b65f414b36df4fc459f Mon Sep 17 00:00:00 2001 From: Alexander Hoppe Date: Thu, 17 Jul 2025 19:42:59 +0000 Subject: [PATCH] initial commit --- .github/workflows/domain-replacer.yaml | 70 ++++++++++++++++++++++++++ domain-replacer/actions.yaml | 11 ++++ domain-replacer/replace.sh | 12 +++++ 3 files changed, 93 insertions(+) create mode 100644 .github/workflows/domain-replacer.yaml create mode 100644 domain-replacer/actions.yaml create mode 100644 domain-replacer/replace.sh diff --git a/.github/workflows/domain-replacer.yaml b/.github/workflows/domain-replacer.yaml new file mode 100644 index 00000000..41dfeca7 --- /dev/null +++ b/.github/workflows/domain-replacer.yaml @@ -0,0 +1,70 @@ +# Copyright (c) 2025 Dell Inc., or its subsidiaries. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 + +# Reusable workflow to update external GitHub domain references in files +name: domain-replacer + +# yamllint sees the below line as a true or false value instead of an 'on' trigger +on: # yamllint disable-line rule:truthy + workflow_call: + +jobs: + + replacedomain: + name: Scan for external GitHub domain + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run domain replacement + uses: hoppea2/common-github-actions/.github/workflows/domain-replacer@main + + - name: Show Git Diff + run: git diff --stat || true + + - name: Commit and push changes + run: | + git config user.name "github-actions" + git config user.email "github-actions@github.com" + + # Check if the branch exists remotely + if git ls-remote --exit-code --heads origin domain-replacement; then + echo "Branch 'domain-replacement' exists. Checking it out." + git fetch origin domain-replacement + git checkout domain-replacement + else + echo "Branch 'domain-replacement' does not exist. Creating it." + git checkout -b domain-replacement + fi + + git add . ':!./.github/workflows/' ':!./.github/workflows/domain-replacer/' + if git diff --cached --quiet; then + echo "No changes to commit." + exit 0 + fi + git commit -m "Replace external GitHub domain with internal Enterprise domain" + git pull --rebase origin domain-replacement || true + git push --force-with-lease origin domain-replacement + + - name: Install GitHub CLI + run: | + sudo apt-get update + sudo apt-get install -y gh + + - name: Create Pull Request with gh CLI + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh pr create \ + --title "Replace external GitHub domain" \ + --body "This PR replaces all references to github.com/dell/ with eos2git.cec.lab.emc.com/CSM/" \ + --base main \ + --head domain-replacement \ + --repo ${{ github.repository }} \ No newline at end of file diff --git a/domain-replacer/actions.yaml b/domain-replacer/actions.yaml new file mode 100644 index 00000000..1e470d1e --- /dev/null +++ b/domain-replacer/actions.yaml @@ -0,0 +1,11 @@ +name: Replace External GitHub Domain +description: Replaces https://github.com/dell/ with https://eos2git.cec.lab.emc.com/CSM/ + +runs: + using: "composite" + steps: + - name: Run domain replacement script + shell: bash + run: | + chmod +x ${{ github.action_path }}/replace.sh + ${{ github.action_path }}/replace.sh "${{ inputs.file-glob }}" \ No newline at end of file diff --git a/domain-replacer/replace.sh b/domain-replacer/replace.sh new file mode 100644 index 00000000..f5be1ea7 --- /dev/null +++ b/domain-replacer/replace.sh @@ -0,0 +1,12 @@ +set -e + +echo "Scanning for files to update..." + + +find . -type f ! -name "go.sum" ! -path "./.github/workflows/*" | while read -r file; do + echo "Checking $file" + if grep -q 'github.com/dell/' "$file"; then + echo "Updating $file" + sed -i 's|github.com/dell/|eos2git.cec.lab.emc.com/CSM/|g' "$file" + fi +done \ No newline at end of file