diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1f4e8d..c3798e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,8 +1,4 @@ -# GitHub Actions configuration **EXAMPLE**, -# MODIFY IT ACCORDING TO YOUR NEEDS! -# Reference: https://docs.github.com/en/actions - -name: tests +name: ci on: push: @@ -27,22 +23,26 @@ jobs: prepare: runs-on: ubuntu-latest outputs: - wheel-distribution: ${{ steps.wheel-distribution.outputs.path }} + wheel-path: ${{ steps.distribution-paths.outputs.wheel }} + tarball-path: ${{ steps.distribution-paths.outputs.tarball }} steps: - uses: actions/checkout@v3 with: {fetch-depth: 0} # deep clone for setuptools-scm - uses: actions/setup-python@v4 - with: {python-version: "3.10"} + with: {python-version: "3.11"} - name: Run static analysis and format checkers run: pipx run pre-commit run --all-files --show-diff-on-failure - name: Build package distribution files run: pipx run --spec 'tox~=3.0' tox -e clean,build - - name: Record the path of wheel distribution - id: wheel-distribution - run: echo "::set-output name=path::$(ls dist/*.whl)" + - name: Record the paths of wheel and source tarball distributions + id: distribution-paths + run: | + echo "wheel=$(ls dist/*.whl)" >> $GITHUB_OUTPUT + echo "tarball=$(ls dist/*.tar.gz)" >> $GITHUB_OUTPUT - name: Store the distribution files for use in other stages - # `tests` and `publish` will use the same pre-built distributions, - # so we make sure to release the exact same package that was tested + # `tests`, `pypi-publish`, and `docker-publish` will use the same + # pre-built distributions, so we make sure to release the exact + # same package that was tested uses: actions/upload-artifact@v3 with: name: python-distribution-files @@ -55,7 +55,7 @@ jobs: matrix: python: - "3.8" - - "3.10" # newest Python that is stable + - "3.11" # newest Python that is stable platform: - ubuntu-latest - macos-latest @@ -71,44 +71,82 @@ jobs: uses: actions/download-artifact@v3 with: {name: python-distribution-files, path: dist/} - name: Run tests (without integration tests) - if: matrix.platform != 'ubuntu-latest' || matrix.python != '3.10' + if: matrix.platform != 'ubuntu-latest' || matrix.python != '3.11' env: SYNAPSE_AUTH_TOKEN: ${{ secrets.SYNAPSE_AUTH_TOKEN }} run: >- pipx run --spec 'tox~=3.0' tox - --installpkg '${{ needs.prepare.outputs.wheel-distribution }}' + --installpkg '${{ needs.prepare.outputs.wheel-path }}' -- -rFEx --durations 10 --color yes -m "not integration" - name: Run tests (with integration tests) - if: matrix.platform == 'ubuntu-latest' && matrix.python == '3.10' + if: matrix.platform == 'ubuntu-latest' && matrix.python == '3.11' env: SYNAPSE_AUTH_TOKEN: ${{ secrets.SYNAPSE_AUTH_TOKEN }} run: >- pipx run --spec 'tox~=3.0' tox - --installpkg '${{ needs.prepare.outputs.wheel-distribution }}' + --installpkg '${{ needs.prepare.outputs.wheel-path }}' -- -rFEx --durations 10 --color yes - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 - if: matrix.platform == 'ubuntu-latest' && matrix.python == '3.10' + if: matrix.platform == 'ubuntu-latest' && matrix.python == '3.11' with: - fail_ci_if_error: true files: coverage.xml name: ${{ matrix.platform }} - py${{ matrix.python }} verbose: true + # CodeCov can be flaky, so this step is not required for success + fail_ci_if_error: false - publish: - needs: test + pypi-publish: + needs: [prepare, test] if: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 - with: {python-version: "3.10"} - - name: Retrieve pre-built distribution files - uses: actions/download-artifact@v3 + with: {python-version: "3.11"} + - uses: actions/download-artifact@v3 with: {name: python-distribution-files, path: dist/} - - name: Publish Package + - name: Publish Python Package to PyPI env: TWINE_REPOSITORY: pypi TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} - run: pipx run --spec 'tox>=3.0,<4.0' tox -e publish + run: pipx run --spec 'tox!=3.0' tox -e publish + + docker-publish: + needs: [prepare, test] + if: ${{ github.event_name == 'push' }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: {name: python-distribution-files, path: dist/} + - uses: docker/setup-qemu-action@v2 + - uses: docker/setup-buildx-action@v2 + - uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/${{ github.repository }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=ref,event=branch + type=sha + - name: Publish Python Package to Docker Hub and GHCR + uses: docker/build-push-action@v3 + with: + platforms: linux/amd64,linux/arm64 + context: . + file: src/docker/Dockerfile + build-args: | + TARBALL_PATH=${{ needs.prepare.outputs.tarball-path }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 7783e78..0000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,52 +0,0 @@ -# This workflow builds and pushes the docker image using docker's v2 action -# which requires explicitly setting up buildx and logging in - -name: Build and publish container to Docker Hub - -on: - push: - tags: ['v[0-9]*', '[0-9]+.[0-9]+*'] # Match tags that resemble a version - branches: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to GHCR - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: | - ghcr.io/${{ github.repository }} - tags: | - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=ref,event=branch - type=sha - - - name: Build and push (all tags and branches) - uses: docker/build-push-action@v3 - with: - platforms: linux/amd64,linux/arm64 - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/src/docker/Dockerfile b/src/docker/Dockerfile new file mode 100644 index 0000000..4c5c882 --- /dev/null +++ b/src/docker/Dockerfile @@ -0,0 +1,11 @@ +FROM python:3.11.1 + +WORKDIR /usr/src/app + +COPY dist/ dist/ + +ARG TARBALL_PATH + +RUN python -m pip install ${TARBALL_PATH} + +CMD [ "python", "-c", "import synapsefs" ] diff --git a/src/docker/build.sh b/src/docker/build.sh new file mode 100644 index 0000000..b62b249 --- /dev/null +++ b/src/docker/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +pipx run --spec 'tox~=3.0' tox -e clean,build + +TARBALL_PATH=$(ls dist/*.tar.gz) +export TARBALL_PATH + +docker build \ + -t fs-synapse \ + -f "${SCRIPT_DIR}/Dockerfile" \ + --build-arg TARBALL_PATH \ + "${SCRIPT_DIR}/../.."