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

Add GHA to copy completed notebooks #132

Merged
Changes from 1 commit
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
117 changes: 117 additions & 0 deletions .github/workflows/copy-completed-notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Copy completed HTML notebooks to training website repository
# Copy completed HTML notebooks from the training-modules repo to this repo
# This action will open a pull request containing completed HTML notebooks

# This is a manually triggered workflow that takes two inputs:
# # The name of the workshop being taught
# # The training-modules repo tag to copy notebooks from
on:
workflow_dispatch:
inputs:
training-module:
type: choice
description: Use the dropdown menu to select which training workshop module this website is being created for.
options:
- "Introduction to R and Tidyverse"
sjspielman marked this conversation as resolved.
Show resolved Hide resolved
- "Introduction to single-cell RNA-seq"
- "Advanced single-cell RNA-seq"
required: true
training-modules-tag:
type: string
description: The `training-modules` repo tag to copy completed notebooks from, e.g. 2023-june
default: "master"
required: true

jobs:
file-completed-notebooks-pr:
runs-on: ubuntu-latest

steps:
- name: Checkout training-modules repository
uses: actions/checkout@v3
with:
repository: AlexsLemonade/training-modules
ref: ${{ github.event.inputs.training-modules-tag }}
path: training-modules

- name: Checkout this repository
uses: actions/checkout@v3
with:
path: main
sjspielman marked this conversation as resolved.
Show resolved Hide resolved

- name: Configure git
run: |
# use global flag since we have multiple repos here
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
sjspielman marked this conversation as resolved.
Show resolved Hide resolved
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"

- name: Get HTML completed notebooks from training-modules
shell: bash
run: |
# The completed notebooks to copy will depend on which workshop module this is.
# For each module, the directory of notebooks to copy are:
# Intro R: intro_to_R_tidyverse/
# Intro scRNA-seq: intro_to_R_tidyverse/ and scRNA-seq/
# Advanced scRNA-seq: advanced-scRNA-seq/

# the url for for this tag of the training-modules repo where files will be downloaded from
base_url=https://raw.githubusercontent.com/AlexsLemonade/training-modules/${{ github.event.inputs.training-modules-tag }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using a URL here rather than just copying the files we already have checked out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why, indeed.


########### Get paths for files to copy, for the given module ############

# We have to cd into training-modules to ensure correct paths come out of `ls`
cd training-modules

# First, intro-to-R-tidyverse notebooks for the intro R workshop
if [[ "${{ github.event.inputs.training-module }}" == "Introduction to R and Tidyverse" ]]; then
notebook_files=`ls intro-to-R-tidyverse/*html`
fi
sjspielman marked this conversation as resolved.
Show resolved Hide resolved

# Second, intro-to-R-tidyverse notebooks and scRNA-seq notebooks for the intro scRNA-seq workshop
if [[ "${{ github.event.inputs.training-module }}" == "Introduction to single-cell RNA-seq" ]]; then
notebook_files=`ls intro-to-R-tidyverse/*html scRNA-seq/*html`
fi

# Third, scRNA-seq-advanced notebooks for the advanced scRNA-seq workshop
if [[ "${{ github.event.inputs.training-module }}" == "Advanced single-cell RNA-seq" ]]; then
notebook_files=`ls scRNA-seq-advanced/*html`
fi

# Now, we have to navigate back to the completed-notebooks directory
cd ../main/completed-notebooks

# curl completed notebook htmls into main/completed-notebooks
for path in ${notebook_files}
do
# test that the path is to an .html file, error if not
# note that at least one notebook is only .html, NOT .nb.html, so we'll just use .html
[[ $path != *.html ]] && echo "'$path' is not an .html file." && exit 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that you used *html for the search, not *.html; it would probably be better to be consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using [0-9]*.html throughout for copying, and we no longer have searching, because the point is to use both repos if we have both repos!

echo ${base_url}/${path}
curl --fail -sO ${base_url}/${path}
done

- name: Create PR with rendered notebooks
uses: peter-evans/create-pull-request@v4
id: cpr
with:
path: main # must be a RELATIVE path to _this_ repo
sjspielman marked this conversation as resolved.
Show resolved Hide resolved
commit-message: Copy completed notebooks from training-modules@${{ github.event.inputs.training-modules-tag }}
signoff: false
branch: auto_copy_completed_notebooks
delete-branch: true
title: 'GHA: Automated transfer of completed notebooks'
body: |
### Description:
This PR was auto-generated from github actions
- Copy completed HTML notebooks from training-modules repository, tag ${{ github.event.inputs.training-modules-tag }}
labels: |
automated
reviewers: $GITHUB_ACTOR


# Write out PR info
- name: Check outputs
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"