From 518126054a5961153bd4f437a4b44682aa54cdf5 Mon Sep 17 00:00:00 2001 From: walkowif <59475134+walkowif@users.noreply.github.com> Date: Fri, 23 Feb 2024 16:05:24 +0100 Subject: [PATCH] Style and roxygen workflow improvements (#216) --- .github/workflows/build-check-install.yaml | 5 ++++ .github/workflows/roxygen.yaml | 7 +++-- .github/workflows/spelling.yaml | 2 +- .github/workflows/style.yaml | 34 +++++++++++++++++----- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-check-install.yaml b/.github/workflows/build-check-install.yaml index c5b19748..55b2f958 100644 --- a/.github/workflows/build-check-install.yaml +++ b/.github/workflows/build-check-install.yaml @@ -302,6 +302,11 @@ jobs: ref: ${{ steps.branch-name.outputs.head_ref_branch }} path: ${{ github.event.repository.name }} repository: ${{ github.event.pull_request.head.repo.full_name }} + # When fetch-depth is set to 1 (default), and if additional commits are added + # to the branch between this step and the 'Set TESTING_DEPTH' step, git might fail + # referencing ${{ github.event.after }} commit + # because it's not the latest commit fetched by this step. + fetch-depth: 0 - name: Checkout repo 🛎 uses: actions/checkout@v4 diff --git a/.github/workflows/roxygen.yaml b/.github/workflows/roxygen.yaml index f3845b21..92947fae 100644 --- a/.github/workflows/roxygen.yaml +++ b/.github/workflows/roxygen.yaml @@ -152,10 +152,11 @@ jobs: echo "Regenerating man pages via auto-update" git config --global user.name "github-actions" git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add -A man/ DESCRIPTION - git commit -m "Roxygen Man Pages Auto Update" + git config pull.rebase false BRANCH_NAME="${{ steps.branch-name.outputs.head_ref_branch }}" - git pull origin ${BRANCH_NAME} + git pull origin ${BRANCH_NAME} || true + git add -A man/ DESCRIPTION + git commit -m "[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update" git push -v origin HEAD:${BRANCH_NAME} || \ (echo "⚠️ Could not push to ${BRANCH_NAME} on $(git remote -v show -n origin | grep Push)" && \ AUTO_UPDATE=failed) diff --git a/.github/workflows/spelling.yaml b/.github/workflows/spelling.yaml index 28707e8e..4903b751 100644 --- a/.github/workflows/spelling.yaml +++ b/.github/workflows/spelling.yaml @@ -112,7 +112,7 @@ jobs: if: github.event_name == 'push' uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: "Update WORDLIST" + commit_message: "[skip ci] Update WORDLIST" file_pattern: "${{ steps.file-pattern.outputs.file-pattern }}" commit_user_name: github-actions commit_user_email: >- diff --git a/.github/workflows/style.yaml b/.github/workflows/style.yaml index 500c9296..ab094d1d 100644 --- a/.github/workflows/style.yaml +++ b/.github/workflows/style.yaml @@ -15,6 +15,11 @@ on: - main workflow_dispatch: workflow_call: + secrets: + REPO_GITHUB_TOKEN: + description: | + Github token with write access to the repo + required: false inputs: auto-update: description: If R code style is not up-to-date, styling will automatically be applied and restyled files will be automatically committed o the branch. @@ -42,17 +47,31 @@ jobs: image: ghcr.io/insightsengineering/rstudio:latest steps: - - name: Checkout Code 🛎 - uses: actions/checkout@v4 - with: - path: ${{ github.event.repository.name }} - fetch-depth: 0 + - name: Setup token 🔑 + id: github-token + run: | + if [ "${{ secrets.REPO_GITHUB_TOKEN }}" == "" ]; then + echo "REPO_GITHUB_TOKEN is empty. Substituting it with GITHUB_TOKEN." + echo "token=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_OUTPUT + else + echo "Using REPO_GITHUB_TOKEN." + echo "token=${{ secrets.REPO_GITHUB_TOKEN }}" >> $GITHUB_OUTPUT + fi + shell: bash - name: Get branch names 🌿 if: inputs.auto-update id: branch-name uses: tj-actions/branch-names@v7 + - name: Checkout Code 🛎 + uses: actions/checkout@v4 + with: + path: ${{ github.event.repository.name }} + fetch-depth: 0 + token: ${{ steps.github-token.outputs.token }} + ref: ${{ steps.branch-name.outputs.head_ref_branch }} + - name: Install styler 👚 run: | install.packages("styler", repos = "https://cloud.r-project.org") @@ -119,9 +138,10 @@ jobs: run: | git config --global user.name 'github-actions' git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' + git config pull.rebase false + git pull origin ${{ steps.branch-name.outputs.head_ref_branch }} || true git add ${{ steps.problem-files.outputs.unstyled-files }} - git commit -m 'Restyle files' - git pull origin ${{ steps.branch-name.outputs.head_ref_branch }} + git commit -m '[skip style] [skip vbump] Restyle files' git push -v origin HEAD:${{ steps.branch-name.outputs.head_ref_branch }} || \ echo "⚠️ Could not push to ${BRANCH_NAME} on $(git remote -v show -n origin | grep Push)" shell: bash