Add caching path #711
This file contains hidden or 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: Python package | |
on: | |
push: | |
paths-ignore: | |
- 'papers/**' | |
- '.github/workflows/daily-workflow.yml' | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ['3.10'] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
file: ./script/Dockerfile | |
push: true | |
tags: ghcr.io/doruirimescu/python-trading:${{ github.ref_name }} | |
cache-from: type=registry,ref=ghcr.io/doruirimescu/python-trading:master | |
cache-to: type=inline | |
build-args: | | |
GH_USERNAME=${{ secrets.GH_USERNAME }} | |
CLONE_TOKEN=${{ secrets.CLONE_TOKEN }} | |
test: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Pull the latest Docker image | |
run: docker pull ghcr.io/doruirimescu/python-trading:${{ github.ref_name }} | |
- name: Run pytest | |
run: docker run --rm ghcr.io/doruirimescu/python-trading:${{ github.ref_name }} python3 -m pytest | |
tag: | |
runs-on: ubuntu-latest | |
needs: [build-and-push, test] | |
if: github.ref == 'refs/heads/master' | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Pull the Docker image | |
run: docker pull ghcr.io/doruirimescu/python-trading:${{ github.ref_name }} | |
- name: Tag the Docker image as 'latest' | |
run: docker tag ghcr.io/doruirimescu/python-trading:${{ github.ref_name }} ghcr.io/doruirimescu/python-trading:latest | |
- name: Push the 'latest' tag to GitHub Container Registry | |
run: docker push ghcr.io/doruirimescu/python-trading:latest |