From 5c88a8cebdbd1263de5a3256d82aca60bbeaf605 Mon Sep 17 00:00:00 2001 From: Pablo Orviz Date: Mon, 11 Dec 2023 16:55:40 +0100 Subject: [PATCH] Do repo-sync & refs update in one single job --- .github/workflows/references.yml | 31 ---------------------- .github/workflows/repo-sync.yml | 37 +++++++++++++++++++++------ .github/workflows/scripts/set_refs.sh | 27 +++++++++---------- 3 files changed, 43 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/references.yml diff --git a/.github/workflows/references.yml b/.github/workflows/references.yml deleted file mode 100644 index 9d942daa..00000000 --- a/.github/workflows/references.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: replace-references -on: - pull_request: - push: - branches: [merge/repo-sync, merge/upstream] - -jobs: - replace_references: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - persist-credentials: false - # extract branch name (either on push or pull_request) - - name: Extract branch name - if: github.event_name != 'pull_request' - shell: bash - run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> "$GITHUB_ENV" - id: extract_branch - - name: Print branch name - if: github.event_name == 'pull_request' - run: echo "BRANCH_NAME=$(echo ${GITHUB_BASE_REF})" >> "$GITHUB_ENV" - - run: bash -x ./.github/workflows/scripts/set_refs.sh $BRANCH_NAME - - run: git status - - uses: gr2m/create-or-update-pull-request-action@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - branch: $BRANCH_NAME - author: "Pablo Orviz " - commit-message: "Update references" diff --git a/.github/workflows/repo-sync.yml b/.github/workflows/repo-sync.yml index b7957961..430bde47 100644 --- a/.github/workflows/repo-sync.yml +++ b/.github/workflows/repo-sync.yml @@ -9,19 +9,40 @@ jobs: name: Repo Sync runs-on: ubuntu-latest steps: + - name: Extract local & upstream repository name (eosc-synergy) + if: contains(github.repository, 'eosc-synergy') + run: | + echo "REPO_NAME_LOCAL=https://github.com/eosc-synergy/FAIR_eva" >> "$GITHUB_ENV" + echo "REPO_NAME_UPSTREAM=https://github.com/IFCA-Advanced-Computing/FAIR_eva" >> "$GITHUB_ENV" + - name: Extract local & upstream repository name (IFCA-Advanced-Computing) + if: contains(github.repository, 'IFCA-Advanced-Computing') + run: | + echo "REPO_NAME_LOCAL=https://github.com/eosc-synergy/FAIR_eva" >> "$GITHUB_ENV" + echo "REPO_NAME_UPSTREAM=https://github.com/IFCA-Advanced-Computing/FAIR_eva" >> "$GITHUB_ENV" + - name: Print local & upstream repository variables + run: | + echo "Using local repository: $REPO_NAME_LOCAL" + echo "Using upstream repository: $REPO_NAME_UPSTREAM" - uses: actions/checkout@v3 with: persist-credentials: false - uses: repo-sync/github-sync@v2 - name: Sync repo to branch + name: Sync repo to branch with: - source_repo: https://github.com/IFCA-Advanced-Computing/FAIR_eva + source_repo: $REPO_NAME_UPSTREAM source_branch: main destination_branch: repo-sync github_token: ${{ secrets.GITHUB_TOKEN }} - # - uses: repo-sync/pull-request@v2 - # name: Create pull request - # with: - # source_branch: repo-sync - # destination_branch: merge/repo-sync - # github_token: ${{ secrets.GITHUB_TOKEN }} + - uses: peter-evans/create-pull-request@v5 + name: Create pull request + with: + base: repo-sync + branch: repo-sync/merge-refs + title: Synchronize repository with upstream contents + - run: bash -x ./.github/workflows/scripts/set_refs.sh $REPO_NAME_LOCAL + - run: git status + - uses: peter-evans/create-pull-request@v5 + name: Create/update pull request + with: + base: repo-sync/merge-refs + title: Update references on repo-sync/merge-refs branch diff --git a/.github/workflows/scripts/set_refs.sh b/.github/workflows/scripts/set_refs.sh index 1c477211..e199c3d9 100755 --- a/.github/workflows/scripts/set_refs.sh +++ b/.github/workflows/scripts/set_refs.sh @@ -1,17 +1,18 @@ #!/bin/bash -BRANCH_NAME=$1 -ORG_LOCAL=eosc-synergy -ORG_UPSTREAM=IFCA-Advanced-Computing +REPO_NAME_LOCAL=$1 +SYNERGY_PATTERN=eosc-synergy +IFCA_PATTERN=ifca-advanced-computing -[[ -z $BRANCH_NAME ]] && echo "Ignoring: no branch name provided" && exit -1 +[[ $# -ne 1 ]] && echo "Ignoring: bad arguments provided" && exit -1 -if [[ $BRANCH_NAME == "merge/repo-sync" ]]; then - echo "Setting references to eosc-synergy" - find . -type f \( -name \*.md -o -name \*.rst -o -name \*.toml -o -name \*.html -o -name \*.cff \) -exec sed -i "s/${ORG_UPSTREAM}\/FAIR_eva/${ORG_LOCAL}\/FAIR_eva/gI" {} + -elif [[ $BRANCH_NAME == "merge/upstream" ]]; then - echo "Setting references to IFCA-Advanced-Computing" - find . -type f \( -name \*.md -o -name \*.rst -o -name \*.toml -o -name \*.html -o -name \*.cff -o -name Dockerfile \) -exec sed -i "s/${ORG_LOCAL}\/FAIR_eva/${ORG_UPSTREAM}\/FAIR_eva/gI" {} + -else - echo "Ignoring: branch name <$BRANCH_NAME> is not in [merge/repo-sync, merge/upstream]" -fi +case ${REPO_NAME_LOCAL,,} in + *eosc-synergy*) + find . -type f \( -name \*.md -o -name \*.rst -o -name \*.toml -o -name \*.html -o -name \*.cff -o -name Dockerfile \) -exec sed -i "s/${IFCA_PATTERN}\/FAIR_eva/${SYNERGY_PATTERN}\/FAIR_eva/gI" {} + + ;; + *ifca-advanced-computing*) + find . -type f \( -name \*.md -o -name \*.rst -o -name \*.toml -o -name \*.html -o -name \*.cff -o -name Dockerfile \) -exec sed -i "s/${SYNERGY_PATTERN}\/FAIR_eva/${IFCA_PATTERN}\/FAIR_eva/gI" {} + + ;; + *) echo "No pattern matching found" + ;; +esac