Skip to content

Commit

Permalink
Updating GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Schuemie authored and Schuemie committed Feb 12, 2021
1 parent 82ca15a commit d1b4ebd
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 50 deletions.
14 changes: 14 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Before you do a pull request, you should always **file an issue** and make sure the package maintainer agrees that it’s a problem, and is happy with your basic proposal for fixing it. We don’t want you to spend a bunch of time on something that we don’t think is a good idea.

Additional requirements for pull requests:

- Adhere to the [Developer Guidelines](https://ohdsi.github.io/MethodsLibrary/developerGuidelines.html) as well as the [OHDSI Code Style](https://ohdsi.github.io/MethodsLibrary/codeStyle.html).

- If possible, add unit tests for new functionality you add.

- Restrict your pull request to solving the issue at hand. Do not try to 'improve' parts of the code that are not related to the issue. If you feel other parts of the code need better organization, create a separate issue for that.

- Make sure you pass R check without errors and warnings before submitting.

- Always target the `develop` branch, and make sure you are up-to-date with the develop branch.

111 changes: 105 additions & 6 deletions .github/workflows/R_CMD_check_Hades.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ jobs:
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
CDM5_ORACLE_CDM_SCHEMA: ${{ secrets.CDM5_ORACLE_CDM_SCHEMA }}
CDM5_ORACLE_OHDSI_SCHEMA: ${{ secrets.CDM5_ORACLE_OHDSI_SCHEMA }}
CDM5_ORACLE_PASSWORD: ${{ secrets.CDM5_ORACLE_PASSWORD }}
CDM5_ORACLE_SERVER: ${{ secrets.CDM5_ORACLE_SERVER }}
CDM5_ORACLE_USER: ${{ secrets.CDM5_ORACLE_USER }}
CDM5_POSTGRESQL_CDM_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_CDM_SCHEMA }}
CDM5_POSTGRESQL_OHDSI_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_OHDSI_SCHEMA }}
CDM5_POSTGRESQL_PASSWORD: ${{ secrets.CDM5_POSTGRESQL_PASSWORD }}
CDM5_POSTGRESQL_SERVER: ${{ secrets.CDM5_POSTGRESQL_SERVER }}
CDM5_POSTGRESQL_USER: ${{ secrets.CDM5_POSTGRESQL_USER }}
CDM5_SQL_SERVER_CDM_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_CDM_SCHEMA }}
CDM5_SQL_SERVER_OHDSI_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_OHDSI_SCHEMA }}
CDM5_SQL_SERVER_PASSWORD: ${{ secrets.CDM5_SQL_SERVER_PASSWORD }}
CDM5_SQL_SERVER_SERVER: ${{ secrets.CDM5_SQL_SERVER_SERVER }}
CDM5_SQL_SERVER_USER: ${{ secrets.CDM5_SQL_SERVER_USER }}

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -62,12 +77,28 @@ jobs:
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install libssh
if: runner.os == 'Linux'
run: |
sudo apt-get install libssh-dev
- name: Install dependencies
run: |
remotes::install_deps(dependencies = TRUE, INSTALL_opts=c("--no-multiarch"))
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Install covr
if: runner.os == 'macOS'
run: |
remotes::install_cran("covr")
shell: Rscript {0}

- name: Remove check folder if exists
if: runner.os == 'macOS'
run: unlink("check", recursive = TRUE)
shell: Rscript {0}

- name: Check
env:
Expand All @@ -77,20 +108,88 @@ jobs:

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
uses: actions/upload-artifact@v2
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check

- name: Upload source package
if: success() && runner.os == 'macOS' && github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
uses: actions/upload-artifact@v2
with:
name: package_tarball
path: check/*.tar.gz

- name: Test coverage
if: runner.os == 'macOS'
run: covr::codecov()
shell: Rscript {0}

Release:
needs: R-CMD-Check

runs-on: macOS-latest

env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

runs-on: ubuntu-20.04
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/master' }}

steps:
- name: First
if: ${{ github.event_name != 'pull_request' && github.branch == 'master' }}

- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Check if version has increased
run: |
echo "new_version="$(perl compare_versions --tag) >> $GITHUB_ENV
- name: Display new version number
if: ${{ env.new_version != '' }}
run: |
echo "${{ env.new_version }}"
- name: Create release
if: ${{ env.new_version != '' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: ${{ env.new_version }}
release_name: Release ${{ env.new_version }}
body: |
See NEWS.md for release notes.
draft: false
prerelease: false

- uses: r-lib/actions/setup-r@v1
if: ${{ env.new_version != '' }}

- name: Install drat
if: ${{ env.new_version != '' }}
run: |
install.packages('drat')
shell: Rscript {0}

- name: Remove any tarballs that already exists
if: ${{ env.new_version != '' }}
run: |
rm -f *.tar.gz
- name: Download package tarball
if: ${{ env.new_version != '' }}
uses: actions/download-artifact@v2
with:
name: package_tarball

- name: Push to drat
if: ${{ env.new_version != '' }}
run: |
bash deploy.sh
- name: Push to BroadSea
if: ${{ env.new_version != '' }}
run: |
perl compare_version --tag && \
bash deploy.sh && \
curl --data "build=true" -X POST https://registry.hub.docker.com/u/ohdsi/broadsea-methodslibrary/trigger/f0b51cec-4027-4781-9383-4b38b42dd4f5/
47 changes: 3 additions & 44 deletions compare_versions
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ $r_major = $1;
$r_minor = $2;
$r_mod = $3;

print "New R version: $r_major-$r_minor-$r_mod\n";

open(GIT_VERSION, "git describe --tags |");
$git = <GIT_VERSION>;
close(GIT_VERSION);
Expand All @@ -20,49 +18,10 @@ $git_major = $1;
$git_minor = $2;
$git_mod = $3;

print "Current git version: $git_major-$git_minor-$git_mod\n";

if ($r_major > $git_major || $r_minor > $git_minor || $r_mod > $git_mod) {
$monotonic = 0;
$new_version = "v$r_major.$r_minor.$r_mod";
} else {
$monotonic = -1;
}

if ($monotonic != 0) {
print "Non-monotonically increasing versions numbers\n";
}

if ($monotonic == 0 & $ARGV[0] eq "--tag") {

open(GIT_TAG, "git tag v$r_major.$r_minor.$r_mod |");

$fail = 0;
while ($line = <GIT_TAG>) {
if ($line =~ /fatal/) {
$fail = 1;
}
print "tag: $line";
} # TODO Check for errors
close(GIT_TAG);
print "tag: END\n\n";

if ($fail eq 1) {
exit(-1);
}

$cmd = "git config user.name \"Marc A. Suchard\"; " .
"git config user.email \"msuchard@ucla.edu\"; " .
"git tag v$r_major.$r_minor.$r_mod ; " .
"git push -q https://\$GH_TOKEN\@github.com/OHDSI/\$PKG_NAME.git --tags";

print "cmd: $cmd\n";

open(GIT_PUSH, "$cmd |");
while ($line = <GIT_PUSH>) {
print "push: $line";
} # TODO Check for errors
close(GIT_PUSH);
print "push: END\n\n";
$new_version = "";
}

exit($monotonic);
print($new_version);
31 changes: 31 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -o errexit -o nounset
addToDrat(){
PKG_REPO=$PWD

## Build package tar ball
export PKG_TARBALL=$(ls *.tar.gz)

cd ..; mkdir drat; cd drat

## Set up Repo parameters
git init
git config user.name "Martijn Schuemie"
git config user.email "[email protected]"
git config --global push.default simple

## Get drat repo
git remote add upstream "https://$GH_TOKEN@github.com/OHDSI/drat.git"
git fetch upstream 2>err.txt
git checkout gh-pages

## Link to local R packages
echo 'R_LIBS=~/Rlib' > .Renviron

Rscript -e "drat::insertPackage('$PKG_REPO/$PKG_TARBALL', \
repodir = '.', \
commit='GitHub Actions release: $PKG_TARBALL run $GITHUB_RUN_ID')"
git push

}
addToDrat

0 comments on commit d1b4ebd

Please sign in to comment.