|
| 1 | +name: R CMD Check |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + branches: |
| 8 | + - main |
| 9 | + - pre-release |
| 10 | + pull_request: |
| 11 | + |
| 12 | +jobs: |
| 13 | + build-install-check: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + container: |
| 16 | + image: ${{ matrix.config.image }}:${{ matrix.config.tag }} |
| 17 | + name: ${{ matrix.config.image }}, version ${{ matrix.config.tag }} |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + config: |
| 22 | + - {image: ghcr.io/insightsengineering/rstudio_4.1.0_bioc_3.13, tag: 'latest'} |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Check if Docker image meets requirements |
| 26 | + run: | |
| 27 | + lsb=$(lsb_release -d) |
| 28 | + [[ ! $lsb =~ "Ubuntu" ]] && exit 1 |
| 29 | +
|
| 30 | + required_pkgs="r-base curl git" |
| 31 | + for PKG in $required_pkgs |
| 32 | + do { |
| 33 | + DPKG_PAGER=cat dpkg -l $PKG |
| 34 | + } |
| 35 | + done |
| 36 | + shell: bash |
| 37 | + |
| 38 | + - name: Gather info from PR |
| 39 | + uses: actions/github-script@v5 |
| 40 | + id: get-pr |
| 41 | + if: github.event_name == 'pull_request' |
| 42 | + with: |
| 43 | + script: | |
| 44 | + const request = { |
| 45 | + owner: context.repo.owner, |
| 46 | + repo: context.repo.repo, |
| 47 | + pull_number: context.issue.number |
| 48 | + } |
| 49 | + core.info(`Getting PR #${request.pull_number} from ${request.owner}/${request.repo}`) |
| 50 | + try { |
| 51 | + const result = await github.rest.pulls.get(request) |
| 52 | + return result.data |
| 53 | + } catch (err) { |
| 54 | + core.setFailed(`Request failed with error ${err}`) |
| 55 | + } |
| 56 | +
|
| 57 | + - name: Checkout repo during PR |
| 58 | + uses: actions/checkout@v2 |
| 59 | + if: github.event_name == 'pull_request' |
| 60 | + with: |
| 61 | + repository: ${{ fromJSON(steps.get-pr.outputs.result).head.repo.full_name }} |
| 62 | + ref: ${{ fromJSON(steps.get-pr.outputs.result).head.ref }} |
| 63 | + path: ${{ github.event.repository.name }} |
| 64 | + |
| 65 | + - name: Checkout repo from push |
| 66 | + uses: actions/checkout@v2 |
| 67 | + if: github.event_name == 'push' |
| 68 | + with: |
| 69 | + path: ${{ github.event.repository.name }} |
| 70 | + |
| 71 | + - name: Print branch name |
| 72 | + run: | |
| 73 | + cd ${{ github.event.repository.name }} |
| 74 | + git branch --show-current |
| 75 | + shell: bash |
| 76 | + |
| 77 | + - name: Run Staged dependencies |
| 78 | + uses: insightsengineering/staged-dependencies-action@v1 |
| 79 | + env: |
| 80 | + GITHUB_PAT: ${{ secrets.REPO_GITHUB_TOKEN }} |
| 81 | + SD_REPO_PATH: ${{ github.event.repository.name }} |
| 82 | + |
| 83 | + - name: Installed packages |
| 84 | + run: | |
| 85 | + Rscript -e 'sessionInfo();as.data.frame(installed.packages()[,c("LibPath","Version")])' |
| 86 | + shell: bash |
| 87 | + |
| 88 | + - name: Build R package |
| 89 | + run: | |
| 90 | + R CMD build ${{ github.event.repository.name }} |
| 91 | + echo "PKGBUILD=$(echo *.tar.gz)" >> $GITHUB_ENV |
| 92 | + shell: bash |
| 93 | + |
| 94 | + - name: Set TESTING_DEPTH |
| 95 | + env: |
| 96 | + COMMIT_NEWEST_MESSAGE: ${{ github.event.head_commit.message }} |
| 97 | + COMMIT_OLDEST_MESSAGE: ${{ github.event.commits[0].message }} |
| 98 | + run: | |
| 99 | + cd ${{ github.event.repository.name }} |
| 100 | + # set TESTING_DEPTH for PR |
| 101 | + if [[ ! -z "${GITHUB_HEAD_REF}" ]]; then |
| 102 | + TESTING_DEPTH=3 |
| 103 | + echo "TESTING_DEPTH=3" >> $GITHUB_ENV |
| 104 | + COMMIT_NEWEST_MESSAGE=$(git log --format=%B -n 1 ${{ github.event.after }}) |
| 105 | + fi |
| 106 | + if [[ $COMMIT_NEWEST_MESSAGE == *"[skip tests]"* ]]; then |
| 107 | + echo "NO_TESTS=1" >> $GITHUB_ENV |
| 108 | + fi |
| 109 | + # default TESTING_DEPTH |
| 110 | + if [[ -z "${TESTING_DEPTH}" ]]; then |
| 111 | + echo "TESTING_DEPTH=1" >> $GITHUB_ENV |
| 112 | + fi |
| 113 | + shell: bash |
| 114 | + |
| 115 | + - name: Print TESTING_DEPTH and NO_TESTS |
| 116 | + run: | |
| 117 | + echo "TESTING_DEPTH = $TESTING_DEPTH" |
| 118 | + echo "NO_TESTS = $NO_TESTS" |
| 119 | +
|
| 120 | +# TODO: if configurable then --as-cran optionally |
| 121 | + - name: Run R CMD CHECK |
| 122 | + run: | |
| 123 | + if [[ -z "${{ env.NO_TESTS }}" ]]; then |
| 124 | + R CMD check ${{ env.PKGBUILD }} |
| 125 | + else |
| 126 | + R CMD check --no-tests ${{ env.PKGBUILD }} |
| 127 | + fi |
| 128 | + shell: bash |
| 129 | + continue-on-error: true |
| 130 | + env: |
| 131 | + # TESTING_DEPTH: 1 |
| 132 | + _R_CHECK_TESTS_NLINES_: 0 |
| 133 | + |
| 134 | + - name: Check whether JUnit XML report exists |
| 135 | + id: check_junit_xml |
| 136 | + uses: andstor/file-existence-action@v1 |
| 137 | + with: |
| 138 | + files: "${{ github.event.repository.name }}.Rcheck/tests/testthat/junit-result.xml" |
| 139 | + |
| 140 | + - name: Publish Unit Test Summary |
| 141 | + uses: EnricoMi/publish-unit-test-result-action@v1 |
| 142 | + if: ${{ steps.check_junit_xml.outputs.files_exists == 'true' && github.event_name == 'pull_request' }} |
| 143 | + with: |
| 144 | + check_name: Unit Tests Summary |
| 145 | + files: "${{ github.event.repository.name }}.Rcheck/tests/testthat/junit-result.xml" |
| 146 | + |
| 147 | + - name: Catch warnings in R CMD check output |
| 148 | + id: catch-errors |
| 149 | + run: | |
| 150 | + x <- tail(readLines("${{ github.event.repository.name }}.Rcheck/00check.log"), 1) |
| 151 | + if (!grepl("^Status", x)) stop("No status line found in R CMD check log") |
| 152 | + if (grepl("ERROR", x)) stop("R CMD check has errors") |
| 153 | + if (grepl("WARNING", x)) stop("R CMD check has warnings") |
| 154 | + shell: Rscript {0} |
| 155 | + |
| 156 | + - name: Upload check results |
| 157 | + if: failure() |
| 158 | + uses: actions/upload-artifact@v2 |
| 159 | + with: |
| 160 | + name: ${{ matrix.config.tag }}-results |
| 161 | + path: ${{ github.event.repository.name }}.Rcheck/00check.log |
| 162 | + |
| 163 | + - name: Install R package |
| 164 | + run: R CMD INSTALL ${{ env.PKGBUILD }} |
| 165 | + shell: bash |
| 166 | + |
| 167 | + - name: Upload package |
| 168 | + if: startsWith(github.ref, 'refs/tags/v') |
| 169 | + uses: actions/upload-artifact@v2 |
| 170 | + with: |
| 171 | + path: ${{ env.PKGBUILD }} |
| 172 | + name: ${{ env.PKGBUILD }} |
| 173 | + |
| 174 | + upload-release-assets: |
| 175 | + name: Upload build tar.gz |
| 176 | + needs: build-install-check |
| 177 | + runs-on: ubuntu-latest |
| 178 | + if: startsWith(github.ref, 'refs/tags/v') |
| 179 | + steps: |
| 180 | + - name: Checkout |
| 181 | + uses: actions/checkout@v2 |
| 182 | + - name: Wait for release to succeed |
| 183 | + timeout-minutes: 2 |
| 184 | + |
| 185 | + with: |
| 186 | + ref: "${{ github.ref }}" |
| 187 | + check-name: 'Release' |
| 188 | + repo-token: ${{ secrets.REPO_GITHUB_TOKEN }} |
| 189 | + wait-interval: 10 |
| 190 | + - name: Set env |
| 191 | + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV |
| 192 | + - name: Get package name |
| 193 | + run: echo "PKGBUILD=${{ github.event.repository.name }}_${{ env.RELEASE_VERSION }}.tar.gz" >> $GITHUB_ENV |
| 194 | + - name: Download artifact |
| 195 | + uses: actions/download-artifact@v2 |
| 196 | + with: |
| 197 | + name: "${{ env.PKGBUILD }}" |
| 198 | + - name: Upload binaries to release |
| 199 | + uses: svenstaro/upload-release-action@v2 |
| 200 | + with: |
| 201 | + repo_token: ${{ secrets.REPO_GITHUB_TOKEN }} |
| 202 | + file: "${{ env.PKGBUILD }}" |
| 203 | + asset_name: "${{ env.PKGBUILD }}" |
| 204 | + tag: "${{ github.ref }}" |
| 205 | + overwrite: false |
0 commit comments