diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..cf6847b --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,66 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + tags: [ "*.*.*" ] + pull_request: + branches: [ "main" ] + +jobs: + + build-calculate-pi: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: joeleehen/pubscraper + flavor: latest=true + tags: | + type=ref, event=branch + type=ref, event=pr + type=semver, pattern={{version}} + + - name: Login to DockerHub + if: github.ref_type == 'tag' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push image + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: ${{ github.ref_type == 'tag' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 0000000..8795916 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,40 @@ +name: Python unit test + +on: + push: + workflow_dispatch: + +jobs: + + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up Python 3.12 + uses: actions/setup-python@v4 + with: + python-version: 3.12 + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-in-project: false + virtualenvs-path: ~/.virtualenvs + + - name: Cache Poetry virtualenv + uses: actions/cache@v3 + id: cache + with: + path: ~/.virtualenvs + key: poetry-${{ hashFiles('**/poetry.lock') }} + restore-keys: | + poetry-${{ hashFiles('**/poetry.lock') }} + + - name: Install Dependencies + run: poetry install + if: steps.cache.outputs.cache-hit != 'true' + + - name: Test with pytest + run: poetry run pytest