feat: build and push docker docker image to ghcr thru GH action #4
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Docker Image to GHCR | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "Dockerfile" | |
- "**/*.R" | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract name & version | |
id: version | |
run: | | |
echo "PACKAGE=$(grep '^Package:' DESCRIPTION | awk '{print $2}')" >> $GITHUB_ENV | |
echo "VERSION=$(grep '^Version:' DESCRIPTION | awk '{print $2}')" >> $GITHUB_ENV | |
- name: Build and Push Docker Image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: .devcontainer/Dockerfile.R | |
tags: | | |
ghcr.io/${{ github.repository_owner }}/${{ env.PACKAGE }}:${{ env.VERSION }} | |
ghcr.io/${{ github.repository_owner }}/${{ env.PACKAGE }}:latest | |
push: true | |
test: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Log in to GHCR | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract name & version | |
id: version | |
run: | | |
echo "PACKAGE=$(grep '^Package:' DESCRIPTION | awk '{print $2}')" >> $GITHUB_ENV | |
echo "VERSION=$(grep '^Version:' DESCRIPTION | awk '{print $2}')" >> $GITHUB_ENV | |
- name: Pull Docker Image for Testing | |
run: | | |
sleep 10 | |
docker pull ghcr.io/${{ github.repository_owner }}/${{ env.PACKAGE }}:latest | |
- name: Run Container Tests | |
run: | |
docker run --rm ghcr.io/${{ github.repository_owner }}/${{ env.PACKAGE | |
}}:${{env.VERSION }} R -e "devtools::test()" |