From 982ddfb14e52c80c3d358724e64a59b0a233b3a3 Mon Sep 17 00:00:00 2001 From: Mark Rudolph Date: Wed, 22 Jan 2025 23:23:49 -0500 Subject: [PATCH] re-work action --- .github/workflows/updates.yaml | 49 +++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/.github/workflows/updates.yaml b/.github/workflows/updates.yaml index 7c3617f..ff5b984 100644 --- a/.github/workflows/updates.yaml +++ b/.github/workflows/updates.yaml @@ -12,19 +12,50 @@ jobs: update: runs-on: ubuntu-latest env: - GH_TOKEN: ${{ github.token }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v3 + - name: Checkout code + uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: coursier/cache-action@v6.4 - - uses: VirtusLab/scala-cli-setup@v1.5 - - name: Create a new branch - run: git checkout -b dependency-update + - name: Setup coursier cache + uses: coursier/cache-action@v6.4 - - run: scala-cli --power dependency-update branch --all + - name: Setup Scala CLI + uses: VirtusLab/scala-cli-setup@v1.5 - - run: | + - name: Check if branch exists on remote + id: branch-check + run: | + if git ls-remote --exit-code --heads origin dependency-update; then + echo "branch_exists=true" >> $GITHUB_ENV + else + echo "branch_exists=false" >> $GITHUB_ENV + fi + + - name: Track or create branch + run: | + if [ "$branch_exists" = "true" ]; then + git fetch origin dependency-update:dependency-update + git checkout dependency-update + else + git checkout -b dependency-update + fi + + - name: Update dependencies + run: | + scala-cli --power dependency-update branch --all + git commit -am "Update dependencies" || echo "No changes to commit" + + - name: Push changes + run: | git push -u origin dependency-update - gh pr create --title "Dependency Updates" --body "Dependency updates from scala-cli" --fill \ No newline at end of file + + - name: Create a Pull Request + run: | + gh pr create \ + --title "Dependency Updates" \ + --body "Dependency updates from scala-cli" \ + --head dependency-update \ + --base main || echo "Pull request already exists or no changes to push" \ No newline at end of file