Skip to content

CI

CI #43

Workflow file for this run

name: CI
on:
schedule:
- cron: '0 10 * * 0' # every Sunday at 10am
push:
branches:
- main
- develop
tags:
- '*.*.*'
pull_request:
env:
docker_repository: tschaffter/rstudio
# github.event.repository.clone_url not available for on: schedule
clone_url: https://github.com/tschaffter/rstudio.git
# github.event.repository.default_branch not available for on: schedule
default_branch: main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Lint Dockerfiles
uses: docker://hadolint/hadolint:latest
with:
entrypoint: hadolint
args: Dockerfile
- name: Check that packages in requirements.txt files are in asc order
run: |
sort -f --check conda/sage-bionetworks/requirements.txt
test:
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set environment variables
run: |
cp .env.example .env
export $(grep -v '^#' .env | xargs -d '\n')
- name: Validate docker-compose.yml
run: docker-compose -f docker-compose.yml config >/dev/null
build-and-publish:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Prepare build
id: prep
run: |
DOCKER_IMAGE=${{ env.docker_repository }}
VERSION=noop
PUSH_IMAGE=false
PUSH_NOTEBOOKS=false
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=weekly
PUSH_IMAGE=true
PUSH_NOTEBOOKS=true
elif [[ $GITHUB_REF == refs/tags/* ]]; then
# VERSION=${GITHUB_REF#refs/tags/}
VERSION=$(cat RSTUDIO_VERSION)
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
PUSH_IMAGE=true
PUSH_NOTEBOOKS=true
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
PUSH_IMAGE=false
PUSH_NOTEBOOKS=true
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR}"
TAGS="$TAGS,${DOCKER_IMAGE}:${MAJOR}"
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}-${GITHUB_SHA::8}"
PUSH_IMAGE=true
PUSH_NOTEBOOKS=true
# elif [ "${{ github.event_name }}" = "push" ]; then
# TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=version_major::${MAJOR}
echo ::set-output name=version_minor::${MINOR}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=push_image::${PUSH_IMAGE}
echo ::set-output name=push_notebooks::${PUSH_NOTEBOOKS}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-single-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-single-buildx
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
builder: ${{ steps.buildx.outputs.name }}
load: true
push: false
platforms: linux/amd64
tags: rstudio-cached:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Create .env
run: |
cp .env.example .env
printf "%s\n" \
"PASSWORD=${{ secrets.RSTUDIO_PASSWORD }}" \
"USERID=$(id -u)" \
"GROUPID=$(id -g)" \
"SYNAPSE_TOKEN=${{ secrets.SYNAPSE_TOKEN }}" | tee -a .env >/dev/null
- name: Generate HTML notebooks
run: |
rm -fr $(pwd)/notebooks/examples/synapse.Rmd
docker run --rm \
--env-file .env \
-v $(pwd)/notebooks:/data \
rstudio-cached:latest \
render /data/examples/*.Rmd
- name: Push image
if: steps.prep.outputs.push_image == 'true'
id: docker_push
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
builder: ${{ steps.buildx.outputs.name }}
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.source=${{ github.repositoryUrl }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# - name: Update Docker Hub repository description
# if: steps.prep.outputs.push_image == 'true'
# uses: peter-evans/dockerhub-description@v2
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_PASSWORD }}
# repository: ${{ env.docker_repository }}
- name: Prepare to publish HTML notebooks to GH Pages
if: steps.prep.outputs.push_notebooks == 'true'
run: |
git clone ${{ env.clone_url }} \
--branch gh-pages --single-branch gh-pages
# Update gh-pages: version specified
NOTEBOOKS_TARGET_DIR=gh-pages/${{ steps.prep.outputs.version }}/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/examples/*.html ${NOTEBOOKS_TARGET_DIR}
# Update gh-pages: latest, major, and minor versions
if [ ! -z "${{ steps.prep.outputs.version_major }}" ]; then
# Update latest (e.g. "1.2.3" => "latest")
NOTEBOOKS_TARGET_DIR=gh-pages/latest/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/examples/*.html ${NOTEBOOKS_TARGET_DIR}
# Update major version (e.g. "1.2.3" => "1")
NOTEBOOKS_TARGET_DIR=gh-pages/${{ steps.prep.outputs.version_major }}/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/examples/*.html ${NOTEBOOKS_TARGET_DIR}
# Update minor version (e.g. "1.2.3" => "1.2")
NOTEBOOKS_TARGET_DIR=gh-pages/${{ steps.prep.outputs.version_minor }}/notebooks
rm -fr ${NOTEBOOKS_TARGET_DIR}
mkdir -p ${NOTEBOOKS_TARGET_DIR}
cp -R notebooks/examples/*.html ${NOTEBOOKS_TARGET_DIR}
fi
cd gh-pages
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .
git commit -m "Update notebooks" -a || true
# The above command will fail if no changes were present, so we ignore
# that.
- name: Push to gh-pages
if: steps.prep.outputs.push_notebooks == 'true'
uses: ad-m/github-push-action@master
with:
branch: gh-pages
directory: gh-pages
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true