diff --git a/.github/workflows/create_pr_on_pr.yml b/.github/workflows/create_pr_on_pr.yml new file mode 100644 index 00000000..3a6cb638 --- /dev/null +++ b/.github/workflows/create_pr_on_pr.yml @@ -0,0 +1,53 @@ +name: Create Translation Branches and PRs + +on: + pull_request: + types: [opened, reopened, synchronize] + + +jobs: + create_translation_branches: + if: startsWith(github.head_ref, 'handbook_v') && endsWith(github.head_ref, '_en') + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up Git + run: | + git config --global user.name 'ntluong95' + git config --global user.email 'ph.ntluong95@gmail.com' + + - name: Install GitHub CLI + run: | + sudo apt update + sudo apt install -y gh + + + - name: Create language branches and PRs + run: | + LANGS=("fr" "es" "vn" "jp" "tr" "pt" "ru") + PR_BRANCH="${{ github.head_ref }}" + VERSION_SUFFIX="${PR_BRANCH#handbook_}" + BASE_BRANCH="main" + + for lang in "${LANGS[@]}"; do + NEW_BRANCH="handbook_${VERSION_SUFFIX/_en/_$lang}" + # Check if the branch already exists + if ! git rev-parse --verify --quiet "${NEW_BRANCH}"; then + git checkout -b "${NEW_BRANCH}" + else + git checkout "${NEW_BRANCH}" + git pull "${PR_BRANCH}" "${NEW_BRANCH}" --rebase + fi + + git fetch origin "${NEW_BRANCH}" + git push origin "${NEW_BRANCH}" + gh pr create --base $BASE_BRANCH --head $NEW_BRANCH --title "Handbook ${VERSION_SUFFIX/_en/} $lang" --body "Automated pull request for $lang handbook version ${VERSION_SUFFIX/_en/}" + done + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + + + diff --git a/.github/workflows/pull_request_template.md b/.github/workflows/pull_request_template.md new file mode 100644 index 00000000..d8fc8f87 --- /dev/null +++ b/.github/workflows/pull_request_template.md @@ -0,0 +1,15 @@ +### 🛠 Changes being made + +Describe the general changes in this PR. +Provide links to each commit in the **List of changes**. + + + + +### 🏎 List of changes + +- [ ] Please do this change [commit #1] + +- [ ] Please do this change [commit #2] + +- [ ] Please do this change [commit #3] \ No newline at end of file diff --git a/.github/workflows/render_book_on_pr.yml b/.github/workflows/render_book_on_pr.yml index 6b6ca855..af97d33c 100644 --- a/.github/workflows/render_book_on_pr.yml +++ b/.github/workflows/render_book_on_pr.yml @@ -1,12 +1,25 @@ name: Render Book on PR to Main on: - pull_request: # change to push later + pull_request_target: + types: [closed] branches: - main jobs: + check-merged: + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'handbook_update') + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.ref }} + build-and-render: + if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'handbook_update') + runs-on: ubuntu-latest + needs: [check-merged] # Ensure this runs only after the check-merged job completes runs-on: ubuntu-latest steps: - name: Check out repository @@ -22,19 +35,21 @@ jobs: - name: Setup R uses: r-lib/actions/setup-r@v2 - - name: Install R Packages + - name: Restore R package from renv run: | - Rscript -e ' - if (!requireNamespace("pacman", quietly = TRUE)) install.packages("pacman") - pacman::p_load( - "tidyverse", "googlesheets4", "learnr", "swirl", "here", "rio", "openxlsx", - "pacman", "renv", "remotes", "linelist", "naniar", "janitor", "gtsummary", - "rstatix", "broom", "lmtest", "easystats", "epicontacts", "EpiNow2", - "EpiEstim", "projections", "incidence2", "i2extras", "epitrix", "distcrete", - "cowplot", "RColorBrewer", "ggnewscale", "DiagrammeR", "gghighlight", "ggrepel", - "plotly", "gganimate", "sf", "tmap", "OpenStreetMap", "spdep", "rmarkdown", - "reportfactory", "officer", "flexdashboard", "shiny", "knitr", "flextable", - "ggtree", "ape", "treeio", "babelquarto", "babeldown")' + install.packages("renv") + renv::restore() +# Rscript -e ' +# if (!requireNamespace("pacman", quietly = TRUE)) install.packages("pacman") +# pacman::p_load( +# "tidyverse", "googlesheets4", "learnr", "swirl", "here", "rio", "openxlsx", +# "pacman", "renv", "remotes", "linelist", "naniar", "janitor", "gtsummary", +# "rstatix", "broom", "lmtest", "easystats", "epicontacts", "EpiNow2", +# "EpiEstim", "projections", "incidence2", "i2extras", "epitrix", "distcrete", +# "cowplot", "RColorBrewer", "ggnewscale", "DiagrammeR", "gghighlight", "ggrepel", +# "plotly", "gganimate", "sf", "tmap", "OpenStreetMap", "spdep", "rmarkdown", +# "reportfactory", "officer", "flexdashboard", "shiny", "knitr", "flextable", +# "ggtree", "ape", "treeio", "babelquarto", "babeldown")' - name: Render Book