|
| 1 | +name: Continuous Delivery |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | + |
| 12 | +env: |
| 13 | + PACKAGE_NAME: "readylog" |
| 14 | + DISTRIBUTION_FILE_INCIPIT: "readylog" |
| 15 | + TEST_DEPENDENCY_GROUP: "test" |
| 16 | + RUN_TEST_COMMAND: "uv run -- pytest --verbose" |
| 17 | + SEMANTIC_RELEASE_CONFIG_FILE: "semantic-release.toml" |
| 18 | + DISTRIBUTION_ARTIFACTS_NAME: "dist" |
| 19 | + DISTRIBUTION_ARTIFACTS_DIR: "dist" |
| 20 | + LOCKFILE_ARTIFACT: "uv.lock" |
| 21 | + |
| 22 | + |
| 23 | +jobs: |
| 24 | + lint: |
| 25 | + name: Lint |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - !step |
| 29 | + name: Setup | Checkout Repository |
| 30 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 31 | + - !step |
| 32 | + name: Lint |
| 33 | + uses: astral-sh/ruff-action@57714a7c8a2e59f32539362ba31877a1957dded1 # v3.5.1 |
| 34 | + variables: |
| 35 | + name: Variables |
| 36 | + needs: lint |
| 37 | + runs-on: ubuntu-latest |
| 38 | + outputs: |
| 39 | + semantic-release-config-file: ${{ steps.set-variables.outputs.semantic-release-config-file }} |
| 40 | + package-name: ${{ steps.set-variables.outputs.package-name }} |
| 41 | + distribution-file-incipit: ${{ steps.set-variables.outputs.distribution-file-incipit }} |
| 42 | + test-dependency-group: ${{ steps.set-variables.outputs.test-dependency-group }} |
| 43 | + run-test-command: ${{ steps.set-variables.outputs.run-test-command }} |
| 44 | + distribution-artifacts-name: ${{ steps.set-variables.outputs.distribution-artifacts-name }} |
| 45 | + distribution-artifacts-dir: ${{ steps.set-variables.outputs.distribution-artifacts-dir }} |
| 46 | + lockfile-artifact: ${{ steps.set-variables.outputs.lockfile-artifact }} |
| 47 | + publish-data: ${{ steps.define-publish-data.outputs.data }} |
| 48 | + steps: |
| 49 | + - name: Setup | Set Variables for Reusable Workflows |
| 50 | + id: set-variables |
| 51 | + run: | |
| 52 | + echo "semantic-release-config-file=${SEMANTIC_RELEASE_CONFIG_FILE}" >> $GITHUB_OUTPUT |
| 53 | + echo "package-name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT |
| 54 | + echo "distribution-file-incipit=${DISTRIBUTION_FILE_INCIPIT}" >> $GITHUB_OUTPUT |
| 55 | + echo "test-dependency-group=${TEST_DEPENDENCY_GROUP}" >> $GITHUB_OUTPUT |
| 56 | + echo "run-test-command=${RUN_TEST_COMMAND}" >> $GITHUB_OUTPUT |
| 57 | + echo "distribution-artifacts-name=${DISTRIBUTION_ARTIFACTS_NAME}" >> $GITHUB_OUTPUT |
| 58 | + echo "distribution-artifacts-dir=${DISTRIBUTION_ARTIFACTS_DIR}" >> $GITHUB_OUTPUT |
| 59 | + echo "lockfile-artifact=${LOCKFILE_ARTIFACT}" >> $GITHUB_OUTPUT |
| 60 | + - name: Setup | Define Publishing Matrix |
| 61 | + id: define-publish-data |
| 62 | + run: | |
| 63 | + echo 'data=[{"registry":"TestPyPI","environment-name":"testpypi","hostname":"test.pypi.org","publish-api-url":"https://test.pypi.org/legacy/"},{"registry":"PyPI","environment-name":"pypi","hostname":"pypi.org","publish-api-url":"https://upload.pypi.org/legacy/"}]' >> $GITHUB_OUTPUT |
| 64 | +
|
| 65 | +
|
| 66 | + build: |
| 67 | + name: Build |
| 68 | + needs: variables |
| 69 | + uses: ./.github/workflows/build.yml |
| 70 | + with: |
| 71 | + semantic-release-config-file: ${{ needs.variables.outputs.semantic-release-config-file }} |
| 72 | + distribution-artifacts-name: ${{ needs.variables.outputs.distribution-artifacts-name }} |
| 73 | + distribution-artifacts-dir: ${{ needs.variables.outputs.distribution-artifacts-dir }} |
| 74 | + lockfile-artifact: ${{ needs.variables.outputs.lockfile-artifact }} |
| 75 | + |
| 76 | + |
| 77 | + test-e2e: |
| 78 | + name: End-to-End Test |
| 79 | + needs: |
| 80 | + - variables |
| 81 | + - build |
| 82 | + uses: ./.github/workflows/test-e2e.yml |
| 83 | + with: |
| 84 | + new-release-detected: ${{ needs.build.outputs.new-release-detected }} |
| 85 | + distribution-artifacts-name: ${{ needs.variables.outputs.distribution-artifacts-name }} |
| 86 | + distribution-artifacts-dir: ${{ needs.variables.outputs.distribution-artifacts-dir }} |
| 87 | + package-name: ${{ needs.variables.outputs.package-name }} |
| 88 | + distribution-file-incipit: ${{ needs.variables.outputs.distribution-file-incipit }} |
| 89 | + test-dependency-group: ${{ needs.variables.outputs.test-dependency-group }} |
| 90 | + run-test-command: ${{ needs.variables.outputs.run-test-command }} |
| 91 | + |
| 92 | + |
| 93 | + release: |
| 94 | + name: Release |
| 95 | + needs: |
| 96 | + - variables |
| 97 | + - build |
| 98 | + - test-e2e |
| 99 | + uses: ./.github/workflows/release.yml |
| 100 | + with: |
| 101 | + new-release-detected: ${{ needs.build.outputs.new-release-detected }} |
| 102 | + semantic-release-config-file: ${{ needs.variables.outputs.semantic-release-config-file }} |
| 103 | + distribution-artifacts-name: ${{ needs.variables.outputs.distribution-artifacts-name }} |
| 104 | + distribution-artifacts-dir: ${{ needs.variables.outputs.distribution-artifacts-dir }} |
| 105 | + lockfile-artifact: ${{ needs.variables.outputs.lockfile-artifact }} |
| 106 | + secrets: inherit |
| 107 | + permissions: |
| 108 | + contents: write |
| 109 | + |
| 110 | + |
| 111 | + # PyPI does not support publishing from reusable workflows yet. Subscribe to: |
| 112 | + # https://github.com/pypi/warehouse/issues/11096 |
| 113 | + # https://github.com/pypa/gh-action-pypi-publish/issues/166 |
| 114 | + publish: |
| 115 | + needs: |
| 116 | + - variables |
| 117 | + - release |
| 118 | + |
| 119 | + strategy: |
| 120 | + matrix: |
| 121 | + publish-data: ${{ fromJSON(needs.variables.outputs.publish-data) }} |
| 122 | + |
| 123 | + name: Publish on ${{ matrix.publish-data.registry }} |
| 124 | + runs-on: ubuntu-latest |
| 125 | + |
| 126 | + if: ${{ needs.release.outputs.new-version-released == 'true' }} |
| 127 | + |
| 128 | + environment: |
| 129 | + name: ${{ matrix.publish-data.environment-name }} |
| 130 | + url: https://${{ matrix.publish-data.hostname }}/p/${{ inputs.package-name }} |
| 131 | + |
| 132 | + permissions: |
| 133 | + contents: read |
| 134 | + id-token: write |
| 135 | + |
| 136 | + steps: |
| 137 | + - !step |
| 138 | + name: Setup | Download Build Artifacts |
| 139 | + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 |
| 140 | + id: artifact-download |
| 141 | + with: |
| 142 | + name: ${{ inputs.distribution-artifacts-name }} |
| 143 | + path: ${{ inputs.distribution-artifacts-dir }} |
| 144 | + |
| 145 | + - !step |
| 146 | + name: Publish Package Distributions to ${{ matrix.publish-data.registry }} |
| 147 | + uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 |
| 148 | + with: |
| 149 | + packages-dir: ${{ inputs.distribution-artifacts-dir }} |
| 150 | + print-hash: true |
| 151 | + verbose: true |
| 152 | + repository-url: ${{ matrix.publish-data.publish-api-url }} |
0 commit comments