Skip to content

Commit

Permalink
Prevent creation of stale branches in s3-sync cronjob (#323)
Browse files Browse the repository at this point in the history
* make synchronization use one branch

* testing

* revert testing changes
  • Loading branch information
James-T-Ardian authored Feb 4, 2024
1 parent 99a0cc8 commit 2ea025f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: S3-synchronization-cronjob

on:
schedule:
- cron: '0 8 * * *' # Everyday at 8am
- cron: '0 8 * * *' # Run every 8am

env:
SYNC_BRANCH_NAME: 's3-sync-branch-91rf9321'

jobs:
sync:
Expand All @@ -12,21 +15,21 @@ jobs:
with:
ref: master
token: ${{ secrets.GH_TOKEN }}
- name: Generate random number
id: random
run: echo "::set-output name=value::$(echo $RANDOM)"
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
- name: Create branch
- name: Delete old sync branch if it exists
run: |
git push -d origin ${{ env.SYNC_BRANCH_NAME }} &>/dev/null || true
- name: Create sync branch
uses: peterjgrainger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
branch: sync-${{ steps.random.outputs.value }}
branch: ${{ env.SYNC_BRANCH_NAME }}
- uses: actions/checkout@v4
with:
ref: sync-${{ steps.random.outputs.value }}
ref: ${{ env.SYNC_BRANCH_NAME }}
token: ${{ secrets.GH_TOKEN }}
- name: create env file
run: |
Expand All @@ -49,6 +52,7 @@ jobs:
git push
- name: create pull request
run: |
gh pr create -B master -H sync-${{ steps.random.outputs.value }} --title 'Cronjob/Sync docs folder with s3' --body 'Created by Github action'
gh pr create -B master -H ${{ env.SYNC_BRANCH_NAME }} --title 'Cronjob/Sync docs folder with s3' --body 'Created by Github action'
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

0 comments on commit 2ea025f

Please sign in to comment.