Skip to content

Commit

Permalink
Update branch from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-phelps committed Mar 1, 2024
2 parents 22e3bd3 + 0c68673 commit 2e691a0
Show file tree
Hide file tree
Showing 27 changed files with 638 additions and 76 deletions.
6 changes: 4 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
^chef\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^\.Rproj\.user$
^\.github$
^\.pre-commit-config\.yaml$
^_pkgdown\.yml$
^chef\.Rproj$
^docs$
^pkgdown$
32 changes: 32 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

export LOCAL_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Array of protected branches
protected_branches=(
"main"
"stage"
"dev"
)




for branch in "${protected_branches[@]}"; do
if [[ "$LOCAL_BRANCH" == "$branch"* ]]; then
echo "Pre-commit hook: Attempt to commit to a protected branch: ${LOCAL_BRANCH}"
echo ""
echo "Checkout a new feature/branchname and push from there."
echo "Then go to github and create a pull request."
exit 1
fi
done


exit 0
58 changes: 58 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

# An example hook script to verify what is about to be pushed. Called by "git
# push" after it has checked the remote status, but before anything has been
# pushed. If this script exits with a non-zero status nothing will be pushed.
#
# This hook is called with the following parameters:
#
# $1 -- Name of the remote to which the push is being done
# $2 -- URL to which the push is being done
#
# If pushing without using a named remote those arguments will be equal.
#
# Information about the commits which are being pushed is supplied as lines to
# the standard input in the form:
#
# <local ref> <local oid> <remote ref> <remote oid>
#
# This sample shows how to prevent push of commits where the log message starts
# with "WIP" (work in progress).

remote="$1"
url="$2"

# Array of protected branches
protected_branches=(
"refs/heads/main/"
"refs/heads/main"
"refs/heads/stage/"
"refs/heads/stage"
"refs/heads/dev/"
"refs/heads/dev"
"refs/heads/testing/precommit"
)

while read local_ref local_sha remote_ref remote_sha; do
for branch in "${protected_branches[@]}"; do
if [[ "$remote_ref" == "$branch"* ]]; then
echo "Pre-push hook: Attempt to commit to a protected branch: ${LOCAL_BRANCH}"
echo ""
echo "Checkout a new feature/branchname and push from there."
echo ""
echo "You can use the following commands to place the changes on a new branch:"
echo "git reset --soft HEAD"
echo "git checkout -b feature/branchname"
echo "git add ."
echo "git commit -m 'Your commit message'"
echo "git push origin feature/branchname"
echo "Then go to github and create a pull request."
exit 1
exit 1
fi
done
done

exit 0

exit 0
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
47 changes: 47 additions & 0 deletions .github/workflows/Check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@



on:
push:
branches: [main, stage, dev]
pull_request:
branches: [main, stage, dev]
workflow_dispatch:

name: Check

jobs:
audit:
name: Audit Dependencies πŸ•΅οΈβ€β™‚οΈ
uses: insightsengineering/r.pkg.template/.github/workflows/audit.yaml@main

licenses:
name: License Check πŸƒ
uses: insightsengineering/r.pkg.template/.github/workflows/licenses.yaml@main

check-reuse:
name: RMD check πŸ“¦
uses: ./.github/workflows/R-CMD-check.yaml

test:
name: Test πŸ§ͺ
uses: ./.github/workflows/Test.yaml

gitleaks:
name: gitleaks πŸ’§
uses: insightsengineering/r.pkg.template/.github/workflows/gitleaks.yaml@main
with:
check-for-pii: true

vbump:
name: Version Bump πŸ€œπŸ€›
if: github.event_name == 'push' && github.ref != 'refs/heads/main'
uses: insightsengineering/r.pkg.template/.github/workflows/version-bump.yaml@main
secrets:
REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# roxygen:
# name: Roxygen πŸ“¦
# uses: ./.github/workflows/Roxygen.yaml


13 changes: 13 additions & 0 deletions .github/workflows/PR_cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: PR cleanup

on:
pull_request:
types: [closed, synchronize]

jobs:
delete_pr_artifacts:
runs-on: ubuntu-latest
steps:
- uses: stefanluptak/delete-old-pr-artifacts@v1
with:
workflow_filename: Check.yaml
50 changes: 50 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
workflow_call:

name: R-CMD-check

# concurrency:
# group: roxygen-${{ github.event.pull_request.number || github.ref }}
# cancel-in-progress: true

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: ubuntu-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'oldrel-1'}
# - {os: ubuntu-latest, r: 'oldrel-2'}
# - {os: ubuntu-latest, r: 'oldrel-3'}
# - {os: ubuntu-latest, r: 'oldrel-4'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
180 changes: 180 additions & 0 deletions .github/workflows/Roxygen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
---
name: Roxygen πŸ…Ύ

on:
workflow_call:
inputs:
# install-system-dependencies:
# description: Check for and install system dependencies
# required: false
# default: false
# type: boolean
# enable-staged-dependencies-check:
# description: Enable staged dependencies YAML check
# required: false
# default: false
# type: boolean
auto-update:
description: If man pages are not up-to-date, they will be automatically updated and committed back to the branch.
required: false
default: false
type: boolean
# sd-direction:
# description: The direction to use to install staged dependencies. Choose between 'upstream', 'downstream' and 'all'
# required: false
# type: string
# default: upstream
package-subdirectory:
description: Subdirectory in the repository, where the R package is located.
required: false
type: string
default: "."
secrets:
REPO_GITHUB_TOKEN:
description: |
Github token with read access to repositories, required for staged.dependencies installation
required: false

# concurrency:
# group: roxygen-${{ github.event.pull_request.number || github.ref }}
# cancel-in-progress: true

jobs:
roxygen:
name: Manual pages check 🏁
runs-on: ubuntu-latest
if: >
!contains(github.event.commits[0].message, '[skip roxygen]')
&& github.event.pull_request.draft == false
container:
image: ghcr.io/insightsengineering/rstudio:latest

steps:
- 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 🌿
id: branch-name
uses: tj-actions/branch-names@v7

- name: Checkout repo (PR) πŸ›Ž
uses: actions/checkout@v4
if: github.event_name == 'pull_request'
# with:
# ref: ${{ steps.branch-name.outputs.head_ref_branch }}
# path: ${{ github.event.repository.name }}
# repository: ${{ github.event.pull_request.head.repo.full_name }}
# token: ${{ steps.github-token.outputs.token }}

- name: Checkout repo πŸ›Ž
uses: actions/checkout@v4
if: github.event_name != 'pull_request'
# with:
# ref: ${{ steps.branch-name.outputs.head_ref_branch }}
# path: ${{ github.event.repository.name }}

- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- name: Setup R dependencies
uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::roxygen2

# - name: Restore SD cache πŸ’°
# uses: actions/cache@v4
# with:
# key: sd-${{ runner.os }}-${{ github.event.repository.name }}
# path: ~/.staged.dependencies

# - name: Run Staged dependencies 🎦
# uses: insightsengineering/staged-dependencies-action@v1
# env:
# GITHUB_PAT: ${{ steps.github-token.outputs.token }}
# with:
# path: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}
# enable-check: ${{ inputs.enable-staged-dependencies-check }}
# run-system-dependencies: ${{ inputs.install-system-dependencies }}
# direction: ${{ inputs.sd-direction }}

- name: Generate man pages πŸ“„
run: |
logfile <- "roxygen_${{ github.event.repository.name }}.log"
con <- file(logfile)
sink(con, append = TRUE, split = TRUE)
sink(con, append = TRUE, type = "message")
roxygen2::roxygenize('.')
sink()
sink(type = "message")
logs <- readLines(logfile)
cat("πŸͺ΅ Log output of 'roxygen2::roxygenize()':\n")
system2("cat", logfile)
error_marker <- grep("Error:", logs)
warnings_marker <- grep("Warning message", logs)
if (length(warnings_marker) > 0) {
cat("⚠ One or more warnings were generated during the roxygen build:\n")
cat(logs[warnings_marker[[1]]:length(logs)], sep = "\n")
stop("Please πŸ™ fix the warnings shown below this message πŸ‘‡")
}
if (length(error_marker) > 0) {
cat("☠ One or more errors were generated during the roxygen build:\n")
cat(logs[error_marker[[1]]:length(logs)], sep = "\n")
stop("Please πŸ™ fix the errors shown below this message πŸ‘‡")
}
shell: Rscript {0}
working-directory: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}

- name: Roxygen check πŸ…Ύ
run: |
AUTO_UPDATE=${{ inputs.auto-update }}
if [[ -n `git status -s | grep -E "man|DESCRIPTION"` ]]
then {
ROXYGEN_VERSION="$(Rscript -e 'packageVersion("roxygen2")' | awk '{print $NF}')"
echo "πŸ™ˆ Manuals are not up-to-date with roxygen comments!"
echo "πŸ”€ The following differences were noted:"
git diff man/* DESCRIPTION
# Attempt to commit and push man-page updates
if [ "${AUTO_UPDATE}" == "true" ]
then {
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 config pull.rebase false
BRANCH_NAME="${{ steps.branch-name.outputs.head_ref_branch }}"
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)
}
fi
# If auto-update is disabled or is unsuccessful, let 'em know to fix manually
if [ "${AUTO_UPDATE}" != "true" ]
then {
echo -e "\nπŸ’» Please rerun the following command on your workstation and push your changes"
echo "--------------------------------------------------------------------"
echo "roxygen2::roxygenize('.')"
echo "--------------------------------------------------------------------"
echo "β„Ή roxygen2 version that was used in this workflow: $ROXYGEN_VERSION"
echo "πŸ™ Please ensure that the 'RoxygenNote' field in the DESCRIPTION file matches this version"
exit 1
}
fi
} else {
echo "πŸ’š Manuals are up-to-date with roxygen comments"
}
fi
shell: bash
working-directory: ${{ github.event.repository.name }}/${{ inputs.package-subdirectory }}
Loading

0 comments on commit 2e691a0

Please sign in to comment.