Skip to content

Copy File from Extended Repo #64

Copy File from Extended Repo

Copy File from Extended Repo #64

Workflow file for this run

name: Copy File from Extended Repo
on:
pull_request:
branches:
- main
workflow_dispatch:
jobs:
copy-file:
runs-on: ubuntu-latest
steps:
- name: Checkout source repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "maximuslotro"
- name: Clone private repository
env:
PAT: ${{ secrets.EXTENDED_REPO_CODE }}
run: |
git clone https://maximuslotro:${PAT}@github.com/maximuslotro/LotrRenewedExtended.git private-repo
git checkout main # Ensure we are on the main branch
- name: Find latest commit for en_us.json
id: get-commit
run: |
cd private-repo
COMMIT_HASH=$(git log -n 1 --pretty=format:%H -- src/generated/resources/assets/lotrextended/lang/en_us.json)
echo "commit_hash=$COMMIT_HASH" >> $GITHUB_OUTPUT
- name: Check if commit hash has changed
id: check-commit
run: |
PREVIOUS_COMMIT_HASH=${{ vars.LASTENUSCOMMENT }}
CURRENT_COMMIT_HASH=${{ steps.get-commit.outputs.COMMIT_HASH }}
if [ "$PREVIOUS_COMMIT_HASH" != "$CURRENT_COMMIT_HASH" ]; then
echo "Commit hash has changed. Proceeding with file push."
else
echo "Commit hash has not changed. Skipping."
exit 0 # Exit successfully without further actions
fi
env:
GITHUB_TOKEN: ${{ secrets.EXTENDED_LANG_REPO_CODE }}
- name: Copy file
run: |
mkdir -p private-repo/upstream/
cp private-repo/src/generated/resources/assets/lotrextended/lang/en_us.json private-repo/upstream/en_us.json
- name: Checkout source repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
clean: false
- name: Check for existing PR
id: pr-check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_ID=$(gh pr list --state open --head update-from-private-lang --json number --limit 1 --jq '.[0].number')
echo "ID: [$PR_ID]"
if [ -z "$PR_ID" ] || [ "$PR_ID" = "[]" ]; then
PR_ID="none"
fi
echo "ID: [$PR_ID]"
echo "pr_id=$PR_ID" >> $GITHUB_OUTPUT
- name: Create or update pull request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH_NAME="update-from-private-lang"
COMMIT_HASH=${{ steps.get-commit.outputs.commit_hash }}
git config pull.ff only
git remote update
git fetch -p
_check_branch=$(git ls-remote --heads origin $BRANCH_NAME)
if [[ -z ${_check_branch} ]]; then
echo "Remote branch does not exist, making!"
git checkout -b $BRANCH_NAME
git push -u origin $BRANCH_NAME
else
echo "Remote branch exists"
git checkout $BRANCH_NAME
git fetch origin # Fetch the latest changes
# Check if the branch is up-to-date
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse @{u})
BASE=$(git merge-base @ @{u})
if [ $LOCAL = $REMOTE ]; then
echo "Branch is up-to-date"
elif [ $LOCAL = $BASE ]; then
echo "Branch needs to pull"
git pull origin $BRANCH_NAME # Pull latest update branch changes
elif [ $REMOTE = $BASE ]; then
echo "Branch needs to push"
else
echo "Branch has diverged"
exit 1
fi
fi
cp private-repo/upstream/en_us.json langs/upstream/en_us.json
ls
rm -r private-repo
git add langs/upstream/en_us.json
git commit -m "Copied en_us.json from private repo, latest edit commit: $COMMIT_HASH"
git push origin $BRANCH_NAME
PR_ID=${{ steps.pr-check.outputs.pr_id }}
if [ "$PR_ID" = "none" ]; then
echo "Made PR"
gh pr create --title "Update en_us.json" --body "Copied en_us.json from private repo, latest edit commit: $COMMIT_HASH" --head $BRANCH_NAME --base main
else
echo "Edited PR"
gh pr edit "$PR_ID" --body "Copied en_us.json from private repo, latest edit en_us commit: $COMMIT_HASH"
fi
- name: Check if commit hash has changed and Change
id: set-commit
run: |
CURRENT_COMMIT_HASH=${{ steps.get-commit.outputs.COMMIT_HASH }}
gh variable set LASTENUSCOMMENT --body "$CURRENT_COMMIT_HASH"
env:
GITHUB_TOKEN: ${{ secrets.EXTENDED_LANG_REPO_CODE }}