Publish to pkg-repo (drat) #136
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# READ-ONLY FILE | |
# | |
# Original file resides in r-hyperspec/pkg-skelton. | |
# DO NOT EDIT in any other repo as these changes will be overwritten. | |
# Edit at r-hyperspec/pkg-skelton, then push there and | |
# this file will be deployed to the other repos. | |
# | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# NOTE 1: | |
# This script automatically detects the repository in which it is run. | |
# No edits are needed except in the "Install Dependencies" section where | |
# one may need to install additional packages according to the needs. | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# NOTE 2: | |
# Each "- name:" task below starts from the same directory, which is: | |
# /home/runner/work/${{ REPOSITORY_NAME }}/${{ REPOSITORY_NAME }} | |
# e.g.: | |
# /home/runner/work/hyperSpec/hyperSpec | |
# Each task is run in its own shell starting from this directory. | |
# This means you have to navigate to the desired directory for each task. | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
# NOTE 3: | |
# If more than one branch given to trigger the workflow, | |
# one may stomp on the other during deployment, so use only one branch. | |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
on: | |
workflow_dispatch: | |
push: | |
branches: [develop, auto-update-test] | |
schedule: | |
# (see https://crontab.guru) | |
- cron: "10 3 * */2 WED" | |
name: Publish to pkg-repo (drat) | |
jobs: | |
drat: | |
if: ${{ github.event.repository.name }} != "pkg-skeleton" | |
runs-on: ${{ matrix.config.os }} | |
name: "drat: ${{ matrix.config.os }} (R-${{ matrix.config.r }})" | |
strategy: | |
fail-fast: false | |
matrix: | |
config: | |
- {os: ubuntu-latest, r: 'release'} | |
# - {os: macOS-latest, r: 'release'} | |
env: | |
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true | |
RSPM: ${{ matrix.config.rspm }} | |
REPO: ${{ github.event.repository.name }} | |
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | |
CACHE_VERSION: 1 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Info | |
run: | | |
echo "GitHub actor: ${{ github.actor }}" | |
- 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 | |
extra-repositories: "https://r-hyperspec.github.io/pkg-repo/" | |
- uses: r-lib/actions/setup-r-dependencies@v2 | |
with: | |
extra-packages: any::drat, any::devtools, local::. | |
needs: check | |
- name: "Install roxygen2==7.2.3" | |
run: | | |
remotes::install_version("roxygen2", "7.2.3") | |
shell: Rscript {0} | |
- name: Roxygenize | |
shell: Rscript {0} | |
run: | | |
roxygen2::roxygenize() | |
- name: Build source package | |
shell: Rscript {0} | |
run: | | |
dir.create("check", showWarnings = FALSE) | |
devtools::build(path = "check") | |
# Above are the steps to build package | |
# Below are the steps to deploy to pkg-repo | |
- name: Configure git | |
# The following configure step is from | |
# https://stackoverflow.com/a/60548651/633251 | |
env: | |
TOKEN: ${{ secrets.DEPLOY_TOKEN }} | |
run: | | |
git config --global url."https://${TOKEN}:[email protected]/".insteadOf "https://github.com/" | |
git config --global user.email "[email protected]" | |
git config --global user.name "${REPO} Deploy Bot" | |
- name: Drat -- clone r-hyperspec/pkg-repo | |
if: success() | |
run: | | |
rm -rf tmp-pkg-repo-dir | |
git clone https://github.com/r-hyperspec/pkg-repo.git tmp-pkg-repo-dir | |
cd tmp-pkg-repo-dir | |
git checkout gh-pages | |
- name: Drat -- insert | |
if: success() | |
shell: Rscript {0} | |
run: | | |
targz <- list.files( | |
path = "check", | |
pattern = "\\.tar\\.gz", | |
full.names = TRUE | |
) | |
drat::insertPackage( | |
file = targz, | |
repodir = "tmp-pkg-repo-dir", | |
action = "archive" | |
) | |
- name: Drat -- commit and push | |
if: success() | |
run: | | |
cd tmp-pkg-repo-dir | |
git add * | |
# .tar.gz files are globally blocked (git ignored) by git, | |
# must add manually and force it | |
git add -f *.tar.gz | |
git commit -m "Automated deploy from ${REPO}" | |
git push origin gh-pages |