From ed16deb675a384cacc8bbf0747c92f9520d7db20 Mon Sep 17 00:00:00 2001 From: Jennings Zhang Date: Mon, 22 Jul 2024 22:29:58 -0400 Subject: [PATCH] First try with GitHub Actions reconfiguration --- .github/workflows/release.yml | 83 +++++++++++++---------------------- .github/workflows/test.yml | 54 +++++++---------------- pyproject.toml | 2 +- 3 files changed, 47 insertions(+), 92 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8908cdd..73cf80b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Publish +name: Release on: push: @@ -11,42 +11,33 @@ env: jobs: release: name: Release - runs-on: ubuntu-latest - env: - POETRY_VERSION: '1.7.1' + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - name: Install rye + uses: eifinger/setup-rye@d4c3ac7b15d8bf2e0b45e2d257c6b5cdbebc3643 # v4.2.1 with: - python-version: '3.10' - # https://github.com/snok/install-poetry#caching-the-poetry-installation - - name: Load cached poetry installation - id: cached-poetry - uses: actions/cache@v4 - with: - path: ~/.local - key: poetry-${{ env.POETRY_VERSION }}-0 # increment to reset cache - - name: Install Python Poetry - if: steps.cached-poetry.outputs.cache-hit != 'true' - uses: snok/install-poetry@c9e8b50048357a728ac0409bae3d7c0a1685118a - with: - version: ${{ env.POETRY_VERSION }} + version: '0.36.0' + enable-cache: true + cache-prefix: ${{ github.workflow }} - - name: Install - run: poetry install --all-extras + - name: Set version + run: rye version '${{ github.ref_name }}' + - run: rye sync + - name: Build + run: rye build --wheel --clean --verbose - name: Publish - run: poetry publish --build --username='__token__' --password='${{ secrets.PYPI_API_TOKEN }}' + run: rye publish --yes --token '${{ secrets.PYPI_API_TOKEN }}' --verbose - name: pdoc run: | - poetry install --with=doc - poetry run pdoc \ + rye run pdoc \ --logo '${{ env.logo }}' \ --footer-text='Version ${{ github.ref_name }}' \ --docformat numpy \ aiochris -o pdoc - name: Deploy docs (version) - uses: JamesIves/github-pages-deploy-action@v4.5.0 + uses: JamesIves/github-pages-deploy-action@v4.6.3 with: branch: gh-pages folder: pdoc @@ -54,44 +45,32 @@ jobs: clean-exclude: 'v*.*.*/' target-folder: "${{ github.ref_name }}" - name: Deploy docs (latest) - uses: JamesIves/github-pages-deploy-action@v4.5.0 + uses: JamesIves/github-pages-deploy-action@v4.6.3 with: branch: gh-pages folder: pdoc clean: false - - name: Get version - id: info - run: echo "version=$(poetry version | awk '{print $2}')" >> "$GITHUB_OUTPUT" + # ref: https://rye.astral.sh/guide/docker/ - name: Create Dockerfile run: | - set -ex - poetry build - cd dist - wheel=$(echo ./aiochris-${{ steps.info.outputs.version }}-py3-*.whl) - if ! [ -f "$wheel" ]; then - echo "::error ::Not a file: $wheel" - exit 1 - fi - now=$(date --rfc-3339=seconds) - cat > Dockerfile << EOF - FROM docker.io/library/python:3.11.5-alpine + python_version="$(< .python_version)" + version="$(rye version)" + now="$(date --rfc-3339=seconds)" + tee Dockerfile << EOF + FROM docker.io/library/python:${python_version}-alpine LABEL org.opencontainers.image.created="$now" \ org.opencontainers.image.authors="Jennings Zhang, FNNDSC " \ org.opencontainers.image.url="${{ github.server_url }}/${{ github.repository }}" \ - org.opencontainers.image.documentation="https://fnndsc.github.io/aiochris" \ org.opencontainers.image.source="${{ github.server_url }}/${{ github.repository }}" \ - org.opencontainers.image.version="${{ steps.info.outputs.version }}" \ + org.opencontainers.image.documentation="https://fnndsc.github.io/aiochris/v$version/" \ + org.opencontainers.image.version="$version" \ org.opencontainers.image.revision="${{ github.ref_name }}" \ org.opencontainers.image.licenses="MIT" \ org.opencontainers.image.title="aiochris Python package" \ org.opencontainers.image.description="Python async client library for ChRIS" - COPY $wheel /tmp/$wheel - RUN pip install --no-input --no-cache-dir --disable-pip-version-check '/tmp/$wheel' && rm -v '/tmp/$wheel' + RUN --mount=source=dist,target=/dist PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir /dist/*.whl EOF - - cat Dockerfile - - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx @@ -102,20 +81,20 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get version + id: get-version + run: echo "version=$(rye version)" >> "$GITHUB_OUTPUT" - name: Build and push - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: push: true - context: ./dist tags: | - ghcr.io/fnndsc/aiochris:${{ steps.info.outputs.version }} + ghcr.io/fnndsc/aiochris:${{ steps.get-version.outputs.version }} ghcr.io/fnndsc/aiochris:latest platforms: linux/amd64,linux/ppc64le,linux/arm64 - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache - name: Draft Github Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: draft: true body: "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ github.ref_name }}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4bee2f5..1d97b76 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: test +name: Test on: push: @@ -6,57 +6,35 @@ on: pull_request: jobs: - local: + test: name: Tests - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 strategy: matrix: python-version: [ '3.11', '3.12' ] - env: - POETRY_VERSION: '1.7.1' steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - name: Install rye + uses: eifinger/setup-rye@d4c3ac7b15d8bf2e0b45e2d257c6b5cdbebc3643 # v4.2.1 with: - python-version: '${{ matrix.python-version }}' - - name: Keyring dependencies - run: | - sudo apt update -y - sudo apt install -y gnome-keyring - # https://github.com/snok/install-poetry#caching-the-poetry-installation - - name: Load cached poetry installation - id: cached-poetry - uses: actions/cache@v4 - with: - path: ~/.local - key: poetry-${{ env.POETRY_VERSION }}-0 # increment to reset cache - - name: Install Python Poetry - if: steps.cached-poetry.outputs.cache-hit != 'true' - uses: snok/install-poetry@c9e8b50048357a728ac0409bae3d7c0a1685118a - with: - version: ${{ env.POETRY_VERSION }} - - - name: miniChRIS + version: '0.36.0' + enable-cache: true + cache-prefix: 'python-v${{ matrix.python-version }}' + - name: Set Python version + run: rye pin --no-update-requires-python '${{ matrix.python-version }}' + - run: rye sync + - name: Start miniChRIS uses: FNNDSC/miniChRIS-docker@master - - - name: Install - run: poetry install --all-extras --with=dev - - name: Test id: test continue-on-error: true # we want to upload coverage, even on failure - # Use wrapper script to access keyring - # https://github.com/hwchen/keyring-rs/blob/4297618e0cf061eacedf6d7c3f164ee4074a3c5d/linux-test.sh run: | - cat > test.sh << EOF - rm -f $HOME/.local/share/keyrings/* - echo -n "test" | gnome-keyring-daemon --unlock # retry tests: they might fail because of CUBE concurrency problems for attempt in {1..5}; do echo " +---------------------+ " echo " | ATTEMPT $attempt | " echo " +---------------------+ " - poetry run pytest --cov=aiochris --cov-report=xml + rye run pytest --cov=aiochris --cov-report=xml if [ "$?" = 0 ]; then if [ "$attempt" != "1" ]; then echo "::warning ::Tests took $attempt attempts." @@ -65,12 +43,10 @@ jobs: fi done exit 1 - EOF - dbus-run-session -- bash -x test.sh - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 with: files: ./coverage.xml env_vars: 'python-${{ matrix.python-version }}' - - name: End test - run: '[ "${{ steps.test.outcome }}" = "success" ]' + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml index 94393e7..ee1c9bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "aiochris" -version = "0.5.0a7" +version = "0.0.0" description = "ChRIS client built on aiohttp" authors = [ { name = "Jennings Zhang", email = "jennings.zhang@childrens.harvard.edu" },