132 lines
3.4 KiB
YAML
132 lines
3.4 KiB
YAML
---
|
|
name: "Build, Test and Publish"
|
|
|
|
"on":
|
|
# run it on push to the default repository branch
|
|
push:
|
|
branches: [master, develop]
|
|
# run it during pull request
|
|
pull_request:
|
|
|
|
env:
|
|
IMAGE_NAME: glenux/teaching-boilerplate
|
|
|
|
jobs:
|
|
build-docker-image:
|
|
name: "Build docker image"
|
|
# run only when code is compiling and tests are passing
|
|
runs-on: ubuntu-latest
|
|
|
|
# steps to perform in job
|
|
steps:
|
|
- name: Set current date as env variable
|
|
run: |
|
|
export BUILD_VERSION=v$(date +'%Y%m%d_%H%M')
|
|
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
|
|
|
|
- name: Checkout code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Build image and save as file
|
|
run: |
|
|
docker build \
|
|
--cache-from $IMAGE_NAME:latest \
|
|
--tag $IMAGE_NAME:latest \
|
|
--build-arg BUILDKIT_INLINE_CACHE=1 \
|
|
"."
|
|
docker save $IMAGE_NAME:latest > /tmp/image.tar
|
|
|
|
- name: Image digest
|
|
run: echo ${{ steps.docker_build.outputs.digest }}
|
|
|
|
- name: Save important variables as extra.env
|
|
run: |
|
|
echo "BUILD_VERSION=$BUILD_VERSION" >> /tmp/extra.env
|
|
cat /tmp/extra.env
|
|
|
|
- name: Upload artifacts
|
|
uses: actions/upload-artifact@v2
|
|
with:
|
|
name: artifacts
|
|
path: |
|
|
/tmp/image.tar
|
|
/tmp/extra.env
|
|
|
|
test-docker-image:
|
|
name: "Test docker image (build PDF and HTML)"
|
|
needs: build-docker-image
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Download artifact
|
|
uses: actions/download-artifact@v2
|
|
with:
|
|
name: artifacts
|
|
path: /tmp
|
|
|
|
- name: Load environment
|
|
run: |
|
|
cat /tmp/extra.env >> $GITHUB_ENV
|
|
|
|
- name: Load image
|
|
run: |
|
|
docker load --input /tmp/image.tar
|
|
docker image ls -a
|
|
|
|
- name: Build HTML for docs
|
|
run: ./scripts/gx-teaching . build-docs-html
|
|
|
|
- name: Build PDF for docs
|
|
run: ./scripts/gx-teaching . build-slides-pdf
|
|
|
|
- name: Build HTML for slides
|
|
run: ./scripts/gx-teaching . build-slides-html
|
|
|
|
- name: Build PDF for slides
|
|
run: ./scripts/gx-teaching . build-slides-pdf
|
|
|
|
push-docker-image:
|
|
name: "Push docker image to registry"
|
|
needs: test-docker-image
|
|
if: github.ref == 'refs/heads/master'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Download artifact
|
|
uses: actions/download-artifact@v2
|
|
with:
|
|
name: artifacts
|
|
path: /tmp
|
|
|
|
- name: Load environment
|
|
run: |
|
|
cat /tmp/extra.env >> $GITHUB_ENV
|
|
|
|
- name: Set up Docker Buildx
|
|
id: buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
- name: Load image
|
|
run: |
|
|
docker load --input /tmp/image.tar
|
|
docker image ls -a
|
|
|
|
- name: Login to DockerHub
|
|
uses: docker/login-action@v1
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Tag images
|
|
run: >
|
|
docker tag
|
|
glenux/teaching-boilerplate:latest
|
|
glenux/teaching-boilerplate:${{ env.BUILD_VERSION }}
|
|
|
|
- name: Build image and push to Docker Hub and GitHub Container Registry
|
|
run: |
|
|
docker push glenux/teaching-boilerplate:latest
|
|
docker push glenux/teaching-boilerplate:${{ env.BUILD_VERSION }}
|
|
#
|