Skip to content

keepCloneUpToDate

keepCloneUpToDate #134

Workflow file for this run

name: keepCloneUpToDate
on:
schedule:
- cron: '0 8 * * *' # 8:00 AM UTC daily
push:
branches:
- public
pull_request:
branches:
- public
workflow_dispatch:
permissions:
contents: write
issues: read
env:
REMOTE_ADDR: 'https://github.com/IbrahimTanyalcin/I-PV.git'
BRANCH_NAME: 'public'
REPO_NAME: 'your-user-name/your-repo'
jobs:
initiate:
runs-on: ubuntu-latest
steps:
- name: Does a public branch exist
id: check_branch
uses: actions/github-script@v7
with:
script: |
const { data: branches } = await github.rest.repos.listBranches({
owner: context.repo.owner,
repo: context.repo.repo,
});
const branchExists = branches.some(branch => branch.name === '${{ env.BRANCH_NAME }}');
core.setOutput('branch_exists', branchExists);
- name: Checkout and Clean
if: ${{ steps.check_branch.outputs.branch_exists == 'true' }}
uses: actions/checkout@v3
with:
repository: ${{ env.REPO_NAME }}
ref: ${{ env.BRANCH_NAME }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
persist-credentials: true
- name: Configure Git
if: ${{ steps.check_branch.outputs.branch_exists == 'true' }}
run: |
git config user.name ${{ secrets.GIT_USER_NAME }}
git config user.email ${{ secrets.GIT_USER_EMAIL }}
git remote add ipvGithub ${{ env.REMOTE_ADDR }}
git fetch ipvGithub master
git fetch --tags -f ipvGithub +master
- name: Rebase and Push Changes if Needed
if: ${{ steps.check_branch.outputs.branch_exists == 'true' }}
run: |
if [ $(git rev-parse @) != $(git rev-parse ipvGithub/master) ]; then
echo "Commits NOT equal, rebasing"
git reset --hard ipvGithub/master
git pull --rebase ipvGithub master
git push --force origin ${{ env.BRANCH_NAME }}:${{ env.BRANCH_NAME }}
git push --tags --force origin ${{ env.BRANCH_NAME }}:${{ env.BRANCH_NAME }}
else
echo "Commits equal, no need to pull"
fi