Skip to content

add github action

add github action #1

# https://github.com/marketplace/actions/build-and-push-docker-images
name: Build, Test and Push Docker Image
runs-on: ubuntu-latest
jobs:
base-image:
on:
push:
paths:
- requirements.txt
- Dockerfile
steps:
# - name: Enable Commit Hash
# uses: prompt/actions-commit-hash@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image and push
uses: docker/build-push-action@v5
with:
push: false
target: base
# tags: mercury/farmers-report-base:${{ steps.commit.outputs.short }}
tags: mercury/farmers-report-base:latest
outputs: type=docker,dest=/tmp/base-image.tar
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: BaseImage
path: /tmp/base-image.tar
test-code:
on:
push
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: BaseImage
path: /tmp
- name: Load image
run: |
docker load --input /tmp/base-image.tar
- name: Test code
run: |
docker run -v $(pwd):/code -w /code mercury/farmers-report-base:latest Rscript /code/tests/testthat.R
docker-image:
on:
pull_request:
branches:
- master
if: github.event.pull_request.merged == true
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build image and push
uses: docker/build-push-action@v5
with:
tags: mercury/farmers-report:latest