From 91d65e5dae2b2a16e4e418c9146e0104db95c2a1 Mon Sep 17 00:00:00 2001 From: Luke Date: Mon, 8 Jul 2024 11:11:19 +0100 Subject: [PATCH] fix: update logic to overwrite branch --- .github/workflows/build.yml | 65 +++++++++++++++---------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b3660e8e..f3a61b86 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,57 +28,44 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 0 ref: ${{github.ref_name}} - token: ${{ secrets.PAT }} - - name: Check if icon-updates branch exists - id: branch-exists - run: echo "branch_exists=$(git ls-remote --heads origin refs/heads/${{env.UPDATE_BRANCH_NAME}} | wc -l)" >> $GITHUB_ENV - - name: Checkout existing branch - if: ${{ env.branch_exists == 1 }} + - name: Create new branch name + id: "branch_name" + run: echo "BRANCH_NAME='${{env.UPDATE_BRANCH_NAME}}-${{github.ref_name}}'" >> $GITHUB_OUTPUT + - name: Install packages + run: npm ci + - name: Compile Typescript files + run: npm run build:fetch-icons + - name: Reset values if action is not scheduled. + if: ${{github.event_name != 'schedule'}} run: | - git checkout ${{env.UPDATE_BRANCH_NAME}} - git pull - - name: Checkout new branch - if: ${{ env.branch_exists == 0 }} - run: git checkout -b ${{env.UPDATE_BRANCH_NAME}} - # - name: Install packages - # run: npm ci - # - name: Compile Typescript files - # run: npm run build:fetch-icons - # - name: Reset values if action is not scheduled. - # if: ${{github.event_name != 'schedule'}} - # run: | - # : > ./.github/fetch_icons/hash.txt - # - name: Fetch icons - # id: "fetch_icons" - # uses: ./.github/fetch_icons - # with: - # figma-access-token: ${{ secrets.FIGMA_PERSONAL_ACCESS_TOKEN }} - # - name: Icons changed - # run: echo ${{ steps.fetch_icons.outputs.files_changed }} - # - name: Get current date - # if: ${{ steps.fetch_icons.outputs.files_changed == 'true'}} - # id: date - # run: echo date=$(date +'%d-%b-%Y') >> $GITHUB_OUTPUT - - name: Do something - run: touch testFile.txt - - name: view changes - run: | - git add . - echo $(git status) + : > ./.github/fetch_icons/hash.txt + - name: Fetch icons + id: "fetch_icons" + uses: ./.github/fetch_icons + with: + figma-access-token: ${{ secrets.FIGMA_PERSONAL_ACCESS_TOKEN }} + - name: TEST DELETE ME + run: touch text.txt + - name: Icons changed + run: echo ${{ steps.fetch_icons.outputs.files_changed }} + - name: Get current date + if: ${{ steps.fetch_icons.outputs.files_changed == 'true'}} + id: date + run: echo date=$(date +'%d-%b-%Y') >> $GITHUB_OUTPUT - name: Push if: ${{ steps.fetch_icons.outputs.files_changed == 'true'}} run: | + git checkout -b ${{steps.branch_name.outputs.BRANCH_NAME}} git config --global user.name "zeta-icons-bot" git config --global user.email "zeta-icons-bot@github.com" git add -A git commit -m "feat: Icon updates ${{ steps.date.outputs.date }}" - git push --set-upstream origin ${{env.UPDATE_BRANCH_NAME}} + git push -f - name: Check if PR exists run: echo "pr_exists=$(gh pr list -H icon-updates --json number -q length)" >> $GITHUB_ENV - name: Create Pull Request if: ${{env.pr_exists == 0 && steps.fetch_icons.outputs.files_changed == 'true'}} - run: gh pr create -B main -H ${{env.UPDATE_BRANCH_NAME}} --title "feat:${{env.UPDATE_BRANCH_NAME}}" --body 'Created by the Zeta Icons bot' + run: gh pr create -B main -H ${{steps.branch_name.outputs.BRANCH_NAME}} --title "feat:${{steps.branch_name.outputs.BRANCH_NAME}}" --body 'Created by the Zeta Icons bot' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}