|
| 1 | +name: Development |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '*.*.*' |
| 7 | +jobs: |
| 8 | + test-changelog: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - uses: actions/checkout@v2 |
| 12 | + - name: Get changelog entry |
| 13 | + id: changelog_reader |
| 14 | + uses: guzman-raphael/changelog-reader-action@v5 |
| 15 | + with: |
| 16 | + path: ./CHANGELOG.md |
| 17 | + - name: Verify changelog parsing |
| 18 | + env: |
| 19 | + TAG_NAME: ${{steps.changelog_reader.outputs.version}} |
| 20 | + RELEASE_NAME: Release ${{steps.changelog_reader.outputs.version}} |
| 21 | + BODY: ${{steps.changelog_reader.outputs.changes}} |
| 22 | + PRERELEASE: ${{steps.changelog_reader.outputs.status == 'prereleased'}} |
| 23 | + DRAFT: ${{steps.changelog_reader.outputs.status == 'unreleased'}} |
| 24 | + run: | |
| 25 | + echo "TAG_NAME=${TAG_NAME}" |
| 26 | + echo "RELEASE_NAME=${RELEASE_NAME}" |
| 27 | + echo "BODY=${BODY}" |
| 28 | + echo "PRERELEASE=${PRERELEASE}" |
| 29 | + echo "DRAFT=${DRAFT}" |
| 30 | + build: |
| 31 | + needs: test-changelog |
| 32 | + runs-on: ubuntu-latest |
| 33 | + strategy: |
| 34 | + matrix: |
| 35 | + include: |
| 36 | + - py_ver: 3.8 |
| 37 | + distro: alpine |
| 38 | + image: djbase |
| 39 | + env: |
| 40 | + PY_VER: ${{matrix.py_ver}} |
| 41 | + DISTRO: ${{matrix.distro}} |
| 42 | + IMAGE: ${{matrix.image}} |
| 43 | + DOCKER_CLIENT_TIMEOUT: "120" |
| 44 | + COMPOSE_HTTP_TIMEOUT: "120" |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v2 |
| 47 | + - name: Compile image |
| 48 | + run: | |
| 49 | + export PKG_NAME=$(python3 -c "print([p for p in __import__('setuptools').find_packages() if '.' not in p][0])") |
| 50 | + export PKG_VERSION=$(cat ${PKG_NAME}/version.py | awk -F\' '/__version__ = / {print $2}') |
| 51 | + export HOST_UID=$(id -u) |
| 52 | + docker-compose -f docker-compose-build.yaml up --exit-code-from element --build |
| 53 | + IMAGE=$(docker images --filter "reference=datajoint/${PKG_NAME}*" \ |
| 54 | + --format "{{.Repository}}") |
| 55 | + TAG=$(docker images --filter "reference=datajoint/${PKG_NAME}*" --format "{{.Tag}}") |
| 56 | + docker save "${IMAGE}:${TAG}" | \ |
| 57 | + gzip > "image-${PKG_NAME}-${PKG_VERSION}-py${PY_VER}-${DISTRO}.tar.gz" |
| 58 | + echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_ENV |
| 59 | + echo "PKG_VERSION=${PKG_VERSION}" >> $GITHUB_ENV |
| 60 | + - name: Add image artifact |
| 61 | + uses: actions/upload-artifact@v2 |
| 62 | + with: |
| 63 | + name: image-${{env.PKG_NAME}}-${{env.PKG_VERSION}}-py${{matrix.py_ver}}-${{matrix.distro}} |
| 64 | + path: "image-${{env.PKG_NAME}}-${{env.PKG_VERSION}}-py${{matrix.py_ver}}-\ |
| 65 | + ${{matrix.distro}}.tar.gz" |
| 66 | + retention-days: 1 |
| 67 | + - if: matrix.py_ver == '3.8' && matrix.distro == 'alpine' |
| 68 | + name: Add pip artifacts |
| 69 | + uses: actions/upload-artifact@v2 |
| 70 | + with: |
| 71 | + name: pip-${{env.PKG_NAME}}-${{env.PKG_VERSION}} |
| 72 | + path: dist |
| 73 | + retention-days: 1 |
| 74 | + publish-release: |
| 75 | + if: github.event_name == 'push' |
| 76 | + needs: build |
| 77 | + runs-on: ubuntu-latest |
| 78 | + env: |
| 79 | + TWINE_USERNAME: ${{secrets.twine_test_username}} |
| 80 | + TWINE_PASSWORD: ${{secrets.twine_test_password}} |
| 81 | + outputs: |
| 82 | + release_upload_url: ${{steps.create_gh_release.outputs.upload_url}} |
| 83 | + steps: |
| 84 | + - uses: actions/checkout@v2 |
| 85 | + - name: Determine package version |
| 86 | + run: | |
| 87 | + PKG_NAME=$(python3 -c "print([p for p in __import__('setuptools').find_packages() if '.' not in p][0])") |
| 88 | + SDIST_PKG_NAME=$(echo ${PKG_NAME} | sed 's|_|-|g') |
| 89 | + PKG_VERSION=$(cat ${PKG_NAME}/version.py | awk -F\' '/__version__ = / {print $2}') |
| 90 | + echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_ENV |
| 91 | + echo "PKG_VERSION=${PKG_VERSION}" >> $GITHUB_ENV |
| 92 | + echo "SDIST_PKG_NAME=${SDIST_PKG_NAME}" >> $GITHUB_ENV |
| 93 | + - name: Get changelog entry |
| 94 | + id: changelog_reader |
| 95 | + uses: guzman-raphael/changelog-reader-action@v5 |
| 96 | + with: |
| 97 | + path: ./CHANGELOG.md |
| 98 | + version: ${{env.PKG_VERSION}} |
| 99 | + - name: Create GH release |
| 100 | + id: create_gh_release |
| 101 | + uses: actions/create-release@v1 |
| 102 | + env: |
| 103 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 104 | + with: |
| 105 | + tag_name: ${{steps.changelog_reader.outputs.version}} |
| 106 | + release_name: Release ${{steps.changelog_reader.outputs.version}} |
| 107 | + body: ${{steps.changelog_reader.outputs.changes}} |
| 108 | + prerelease: ${{steps.changelog_reader.outputs.status == 'prereleased'}} |
| 109 | + draft: ${{steps.changelog_reader.outputs.status == 'unreleased'}} |
| 110 | + - name: Fetch image artifact |
| 111 | + uses: actions/download-artifact@v2 |
| 112 | + with: |
| 113 | + name: image-${{env.PKG_NAME}}-${{env.PKG_VERSION}}-py3.8-alpine |
| 114 | + - name: Fetch pip artifacts |
| 115 | + uses: actions/download-artifact@v2 |
| 116 | + with: |
| 117 | + name: pip-${{env.PKG_NAME}}-${{env.PKG_VERSION}} |
| 118 | + path: dist |
| 119 | + - name: Publish pip release |
| 120 | + run: | |
| 121 | + export HOST_UID=$(id -u) |
| 122 | + docker load < "image-${{env.PKG_NAME}}-${PKG_VERSION}-py3.8-alpine.tar.gz" |
| 123 | + docker-compose -f docker-compose-build.yaml run \ |
| 124 | + -e TWINE_USERNAME=${TWINE_USERNAME} -e TWINE_PASSWORD=${TWINE_PASSWORD} element \ |
| 125 | + sh -lc "pip install twine && python -m twine upload --repository testpypi dist/*" |
| 126 | + - name: Determine pip artifact paths |
| 127 | + run: | |
| 128 | + echo "PKG_WHEEL_PATH=$(ls dist/${PKG_NAME}-*.whl)" >> $GITHUB_ENV |
| 129 | + echo "PKG_SDIST_PATH=$(ls dist/${SDIST_PKG_NAME}-*.tar.gz)" >> $GITHUB_ENV |
| 130 | + - name: Upload pip wheel asset to release |
| 131 | + uses: actions/upload-release-asset@v1 |
| 132 | + env: |
| 133 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 134 | + with: |
| 135 | + upload_url: ${{steps.create_gh_release.outputs.upload_url}} |
| 136 | + asset_path: ${{env.PKG_WHEEL_PATH}} |
| 137 | + asset_name: pip-${{env.PKG_NAME}}-${{env.PKG_VERSION}}.whl |
| 138 | + asset_content_type: application/zip |
| 139 | + - name: Upload pip sdist asset to release |
| 140 | + uses: actions/upload-release-asset@v1 |
| 141 | + env: |
| 142 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 143 | + with: |
| 144 | + upload_url: ${{steps.create_gh_release.outputs.upload_url}} |
| 145 | + asset_path: ${{env.PKG_SDIST_PATH}} |
| 146 | + asset_name: pip-${{env.SDIST_PKG_NAME}}-${{env.PKG_VERSION}}.tar.gz |
| 147 | + asset_content_type: application/gzip |
0 commit comments