From ebebdb889eb9f016ac1a30a69c0579254ccf6ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=BA=E5=8F=A3=E3=83=AC=E3=82=A4?= Date: Sun, 10 Nov 2024 13:54:41 +0100 Subject: [PATCH] Made some changes to the GitHub Actions workflows --- .github/workflows/buildndeploy.yml | 8 ++++++++ .github/workflows/prcheck.yml | 8 ++++++++ expire-old-content.js | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/buildndeploy.yml b/.github/workflows/buildndeploy.yml index 98ca10b..c618058 100644 --- a/.github/workflows/buildndeploy.yml +++ b/.github/workflows/buildndeploy.yml @@ -21,6 +21,14 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Determine Workflow Branch + run: echo "TARGET_BRANCH=${{ github.event.pull_request.head.ref || github.ref_name }}" >> $GITHUB_ENV + + - name: Switch to Workflow Branch + run: git checkout ${{ env.TARGET_BRANCH }} - name: Setup Node uses: actions/setup-node@v4 diff --git a/.github/workflows/prcheck.yml b/.github/workflows/prcheck.yml index 97e7bab..b61bc8a 100644 --- a/.github/workflows/prcheck.yml +++ b/.github/workflows/prcheck.yml @@ -12,6 +12,14 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Determine Workflow Branch + run: echo "TARGET_BRANCH=${{ github.event.pull_request.head.ref || github.ref_name }}" >> $GITHUB_ENV + + - name: Switch to Workflow Branch + run: git checkout ${{ env.TARGET_BRANCH }} - name: Setup Node uses: actions/setup-node@v4 diff --git a/expire-old-content.js b/expire-old-content.js index 321c79c..a7bc7e8 100644 --- a/expire-old-content.js +++ b/expire-old-content.js @@ -127,13 +127,17 @@ function updateCronSchedule() { // Step 3: Commit and push changes if any files were modified function commitAndPushChanges(hasComponentChanges) { + if (process.env.TARGET_BRANCH === undefined) { + console.error('TARGET_BRANCH is not set. Not committing or pushing changes.'); + return; + } try { if (hasComponentChanges) { execSync(`git config user.email "41898282+github-actions[bot]@users.noreply.github.com"`); execSync(`git config user.name "Anti-Social Bot"`); execSync(`git add .`); execSync(`git commit -m "Remove expired images and update cron schedule"`); - execSync('git push'); + execSync(`git push origin HEAD:${process.env.TARGET_BRANCH}`); console.log('Changes pushed to repository.'); } else { console.log('No changes to commit.');