Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make test sync better and more customizeable #404

Merged
merged 6 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 31 additions & 50 deletions .github/test-sync.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,33 @@
# Candace Savonen Aug 2021
# For info on how to update this file see: https://github.com/marketplace/actions/repo-file-sync-action#%EF%B8%8F-sync-configuration

group:
# Repositories to recieve changes
repos: |
jhudsl/Reproducibility_in_Cancer_Informatics

###ADD NEW REPO HERE following the format above#
repos: jhudsl/OTTR_Template_Test
files:
- source: .github/workflows/render-bookdown.yml
dest: .github/workflows/render-bookdown.yml
- source: .github/workflows/render-preview.yml
dest: .github/workflows/render-preview.yml
- source: .github/workflows/docker-build-test.yml
dest: .github/workflows/docker-build-test.yml
- source: .github/workflows/transfer-rendered-files.yml
dest: .github/workflows/transfer-rendered-files.yml
- source: .github/workflows/style-and-sp-check.yml
dest: .github/workflows/style-and-sp-check.yml
- source: .github/workflows/url-checker.yml
dest: .github/workflows/url-checker.yml
- source: .github/workflows/release-notes.yml
dest: .github/workflows/release-notes.yml
- source: .github/workflows/delete-preview.yml
dest: .github/workflows/delete-preview.yml
- source: .github/ISSUE_TEMPLATE/course-problem-report.md
dest: .github/ISSUE_TEMPLATE/course-problem-report.md
- source: .github/ISSUE_TEMPLATE/course-content-add.md
dest: .github/ISSUE_TEMPLATE/course-content-add.md
- source: scripts/spell-check.R
dest: scripts/spell-check.R
- source: scripts/git_repo_check.R
dest: scripts/git_repo_check.R
- source: code_of_conduct.md
dest: code_of_conduct.md
- source: style-sets
dest: style-sets

###### TO ADD NEW REPOSITORY USE THIS FORMAT; Feel free to add/drop files that
# you specifically would like synced (or not).
#
# # Repositories to receive changes
# repos: |
# org/repo_name
# # Files which should be updated
# - source: .github/workflows/
# dest: .github/workflows/
# - source: scripts/
# dest: scripts/
# - source: docker/
# dest: docker/
- source: .github/workflows/render-bookdown.yml
dest: .github/workflows/render-bookdown.yml
- source: .github/workflows/render-preview.yml
dest: .github/workflows/render-preview.yml
- source: .github/workflows/docker-build-test.yml
dest: .github/workflows/docker-build-test.yml
- source: .github/workflows/transfer-rendered-files.yml
dest: .github/workflows/transfer-rendered-files.yml
- source: .github/workflows/style-and-sp-check.yml
dest: .github/workflows/style-and-sp-check.yml
- source: .github/workflows/url-checker.yml
dest: .github/workflows/url-checker.yml
- source: .github/workflows/release-notes.yml
dest: .github/workflows/release-notes.yml
- source: .github/workflows/delete-preview.yml
dest: .github/workflows/delete-preview.yml
- source: .github/ISSUE_TEMPLATE/course-problem-report.md
dest: .github/ISSUE_TEMPLATE/course-problem-report.md
- source: .github/ISSUE_TEMPLATE/course-content-add.md
dest: .github/ISSUE_TEMPLATE/course-content-add.md
- source: scripts/spell-check.R
dest: scripts/spell-check.R
- source: scripts/get_spell_errors.R
dest: scripts/get_spell_errors.R
- source: scripts/git_repo_check.R
dest: scripts/git_repo_check.R
- source: code_of_conduct.md
dest: code_of_conduct.md
- source: style-sets
dest: style-sets
32 changes: 6 additions & 26 deletions .github/workflows/render-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ permissions: write-all
jobs:
# This workflow contains a single job called "build-all"
build-all:
# The type of runner that the job will run on
runs-on: ubuntu-latest
container:
image: jhudsl/course_template
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand All @@ -25,40 +26,20 @@ jobs:
run: |
git config --local user.email "itcrtrainingnetwork@gmail.com"
git config --local user.name "jhudsl-robot"
git config pull.rebase false

# Get on the preview branch if it exists. If it doesn't create it.
branch_name='preview-${{ github.event.pull_request.number }}'
git rev-parse --quiet --verify $branch_name >/dev/null && exists=true || exists=false

if [[ $exists == true ]];
then
git checkout $branch_name
git pull --set-upstream origin $branch_name --allow-unrelated-histories
else
git checkout -b $branch_name
fi

git checkout -b "preview-${{ github.event.pull_request.number }}"
rm -r docs/*

# Run bookdown rendering
- name: Run bookdown render
id: bookdown
run: |
docker run \
--mount type=bind,target=/home/rstudio,source=$PWD \
jhudsl/course_template \
Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all')"
run: Rscript -e "bookdown::render_book('index.Rmd', output_format = 'all')"

##### If you do not wish to host your course on Coursera, you can delete this section #####
# Run Coursera version
- name: Run Coursera version of render
id: coursera
run: |
docker run \
--mount type=bind,target=/home/rstudio,source=$PWD \
jhudsl/course_template \
Rscript -e "leanbuild::render_coursera()"
run: Rscript -e "leanbuild::render_coursera()"

##### End of Coursera rendering section ########################################

Expand All @@ -81,8 +62,7 @@ jobs:
echo ::set-output name=changes::$(echo 'changes')
git add . --force
git commit -m 'Render bookdown preview'
git pull --set-upstream origin "preview-${{ github.event.pull_request.number }}" --allow-unrelated-histories
git push --force --set-upstream origin "preview-${{ github.event.pull_request.number }}"
git push --force origin "preview-${{ github.event.pull_request.number }}"
else
echo ::set-output name=changes::$(echo 'no_changes')
fi
Expand Down
32 changes: 13 additions & 19 deletions .github/workflows/test-send-updates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,37 @@
name: Test Sync Files

on:
release:
types: [prereleased, published]
workflow_dispatch:
inputs:
prtag:
description: 'Tag to use?'
repo:
description: 'What repo to test on e.g. jhudsl/OTTR_Template_Test'
required: true
default: 'null'
default: 'jhudsl/OTTR_Template_Test'

jobs:
sync:
test-sync:
runs-on: ubuntu-latest
container:
image: jhudsl/course_template

steps:
- name: Checkout Repository
uses: actions/checkout@master

- name: login as jhudsl-robot
- name: Login as jhudsl-robot
run: |
git config --local user.email "itcrtrainingnetwork@gmail.com"
git config --local user.name "jhudsl-robot"

- name: Get the version
id: get_tag
- name: Set up test-sync.yml
run: |
if [ github.event.inputs.prtag == 'null' ]
then
echo ::set-output name=version::$(echo $GITHUB_REF | cut -d / -f 3)
fi
if [ github.event.inputs.prtag != 'null' ]
then
echo ::set-output name=version::${{ github.event.inputs.prtag }}
fi

cp .github/sync.yml .github/test-sync.yml
# Switch out repo argument
Rscript --vanilla scripts/switch_sync_repo.R --repo ${{ github.event.inputs.repo }}

- name: Run Mechanics File Sync
uses: BetaHuhn/repo-file-sync-action@v1.7.1
with:
GH_PAT: ${{ secrets.GH_PAT }}
COMMIT_BODY: release-${{ steps.get_tag.outputs.version }}
COMMIT_BODY: "test-run"
CONFIG_PATH: .github/test-sync.yml
37 changes: 37 additions & 0 deletions scripts/switch_sync_repo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env Rscript

# This script switches the repo entry for the yaml file to whatever is specified
# Written by Candace Savonen Jan 2022

if (!("optparse" %in% installed.packages())){
install.packages("optparse")
}

library(optparse)

option_list <- list(
optparse::make_option(
c("--repo"),
type = "character",
default = "jhudsl/OTTR_Template_Test",
help = "GitHub repository name, e.g. jhudsl/OTTR_Template_Test",
)
)

# Read the arguments passed
opt_parser <- optparse::OptionParser(option_list = option_list)
opt <- optparse::parse_args(opt_parser)

# Find .git root directory
root_dir <- rprojroot::find_root(rprojroot::has_dir(".git"))

# Get test sync yaml path
sync_file_path <- file.path(root_dir, ".github", "test-sync.yml")

yaml_contents <- yaml::yaml.load_file(sync_file_path)

# Switch out repo
yaml_contents$group$repos <- opt$repo

yaml::write_yaml(yaml_contents, sync_file_path)