diff --git a/.github/workflows/python-build.yml b/.github/workflows/python-build.yml index 94778e4..7d5b874 100644 --- a/.github/workflows/python-build.yml +++ b/.github/workflows/python-build.yml @@ -21,7 +21,7 @@ on: description: "env to set for docker compose as a JSON string" required: false type: string - default: "" + default: "{}" python-versions-to-test: description: "List of versions of python to run, as a JSON string" required: false @@ -171,7 +171,7 @@ jobs: - name: Stand up required service containers, and run code generation if: inputs.docker-container != '' - env: ${{ fromJSON(inputs.docker-compose-env }} + env: ${{ fromJSON(inputs.docker-compose-env) }} run: | docker compose up ${{ inputs.docker-container }} diff --git a/.github/workflows/python-lib-release.yml b/.github/workflows/python-lib-release.yml index 6aaa2af..c0f88da 100644 --- a/.github/workflows/python-lib-release.yml +++ b/.github/workflows/python-lib-release.yml @@ -27,12 +27,16 @@ on: description: "env to set for docker compose as a JSON string" required: false type: string - default: "" + default: "{}" python-version: description: "Python versions to run 'build'" required: false type: string default: 3.10 + package-release-version: + description: "Version to release" + required: false + type: string secrets: CI_GITHUB_TOKEN: @@ -88,6 +92,7 @@ jobs: - name: Release checks and update version for release id: check + if: ${{ !inputs.package-release-version }} run: | /scripts/release-checks.sh --python pyproject.toml /scripts/finalize-version.sh --python pyproject.toml @@ -95,6 +100,23 @@ jobs: echo "version=$version" >> "${GITHUB_OUTPUT}" shell: bash + - name: Release checks and update version for release (version override) + id: version-override + if: ${{ inputs.package-release-version }} + run: | + git config --global user.email "ci@zepben.com" + git config --global user.name "CI" + git checkout -b release + ls + echo "version=${{ inputs.package-release-version }}" >> "${GITHUB_OUTPUT}" + sed -i 's#version = "[0-9]\.[0-9]\.[0-9]b[0-9]"#version = "${{ inputs.package-release-version }}"#g' pyproject.toml + sed -i 's#version = "edge"#version = "0.0.0b1"#g' pyproject.toml + cat pyproject.toml + git add pyproject.toml + git commit -m "Release ${{ inputs.package-release-version }} [skip ci]" --allow-empty + git push -u origin release + shell: bash + - name: Cache licence-check uses: actions/cache@v4 with: @@ -141,6 +163,7 @@ jobs: - name: Test changelog format id: changelog + if: ${{ !inputs.package-release-version }} shell: bash run: | changelog=$(sed -n -E "/${{ steps.check.outputs.version }}/,/## [[0-9]+\.[0-9]+\.[0-9]+]/ { /## \[/d;p }" changelog.md) @@ -180,7 +203,6 @@ jobs: needs: [release-checks, build-docs] if: always() && !failure() && !cancelled() runs-on: ubuntu-latest - container: python:${{ inputs.python-version }} outputs: artifact: ${{ steps.build.outputs.artifact }} steps: @@ -196,6 +218,12 @@ jobs: - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ inputs.python-version }} + architecture: 'x64' + + - name: Checkout release branch run: | git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" @@ -210,7 +238,8 @@ jobs: echo "[pypi]" > ~/.pypirc echo "username = __token__" >> ~/.pypirc echo "password = $PYPI_API_TOKEN" >> ~/.pypirc - echo "\n" >> ~/.pypirc + echo >> ~/.pypirc + cat ~/.pypirc - name: Login to Docker Hub if: inputs.docker-container != '' @@ -222,17 +251,16 @@ jobs: - name: Stand up required service containers, and run code generation if: inputs.docker-container != '' - env: ${{ fromJSON(inputs.docker-compose-env }} + env: ${{ fromJSON(inputs.docker-compose-env) }} run: | docker compose up ${{ inputs.docker-container }} - name: Build and publish id: build run: | - tox -e py${{ inputs.python-version }} + tox -e build twine upload --non-interactive --config-file ~/.pypirc dist/* - artifact_id=$(cat pyproject.toml | grep '[[:space:]]*name[[:space:]]*=[[:space:]]*".*"$' | cut -d\" -f2 | tr -d '"' | sed 's-\.-_-g') - artifact="${artifact_id}-${{ needs.release-checks.outputs.version }}-py3-none-any.whl" + artifact=`ls dist | grep py3-none-any.whl` echo "artifact=$artifact" >> "${GITHUB_OUTPUT}" echo "artifact-path=dist/$artifact" >> "${GITHUB_OUTPUT}" @@ -286,6 +314,7 @@ jobs: - name: Merge and Tag id: merge + if: ${{ !inputs.package-release-version }} run: | git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" git fetch --all @@ -298,6 +327,20 @@ jobs: shell: bash continue-on-error: true + - name: Tag and delete release branch (version override) + id: tag + if: ${{ inputs.package-release-version }} + run: | + git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" + git fetch --all + git branch -a + git checkout origin/release + git tag "v${{ inputs.package-release-version }}" + git push --tags + echo "tag=v${{ inputs.package-release-version }}" >> "${GITHUB_OUTPUT}" + shell: bash + continue-on-error: true + - name: Delete release branch if merge failed and fail if: steps.merge.outcome == 'failure' run: | @@ -321,7 +364,7 @@ jobs: continue-on-error: true - name: Create Release and upload assets - if: success() + if: ${{ success() && !inputs.package-release-version }} id: create_release uses: softprops/action-gh-release@v1 env: @@ -335,9 +378,24 @@ jobs: built-artifacts/${{ needs.deploy.outputs.artifact }} continue-on-error: true + - name: Create Release and upload assets (version-override) + if: ${{ success() && inputs.package-release-version }} + uses: softprops/action-gh-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.tag.outputs.tag }} + body_path: latest_changelog.txt + draft: false + prerelease: false + files: | + built-artifacts/${{ needs.deploy.outputs.artifact }} + continue-on-error: true + + update-version: needs: [create-release] - if: always() && !failure() && !cancelled() + if: ${{ always() && !failure() && !cancelled() && !inputs.package-release-version }} runs-on: ubuntu-latest container: zepben/pipeline-basic env: @@ -372,3 +430,28 @@ jobs: PRODUCT: ${{ needs.build-docs.outputs.product }} ARTIFACT: ${{ needs.build-docs.outputs.artifact }} secrets: inherit + + + delete-release-branch: + needs: [create-release, update-version] + if: failure() + runs-on: ubuntu-latest + env: + DEBUG: ${{ secrets.DEBUG }} + GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }} + SLACK_NOTIFICATION: ${{ secrets.SLACK_NOTIFICATION }} + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + steps: + - uses: actions/checkout@v4 + with: + token: ${{ env.GITHUB_TOKEN }} + + - name: Delete release branch + run: | + git config --global user.email "ci@zepben.com" + git config --global user.name "CI" + git push origin -d release + echo "There was a failure in the workflow. release branch was deleted." + exit 0 + shell: bash + diff --git a/.github/workflows/python-lib-snapshot.yml b/.github/workflows/python-lib-snapshot.yml index 2a26c89..c702f72 100644 --- a/.github/workflows/python-lib-snapshot.yml +++ b/.github/workflows/python-lib-snapshot.yml @@ -22,6 +22,11 @@ on: description: "Docker container to run as part of build" required: false type: string + docker-compose-env: + description: "env to set for docker compose as a JSON string" + required: false + type: string + default: "{}" python-version: description: "Python versions to run 'build'" required: false @@ -147,6 +152,7 @@ jobs: - name: Stand up required service containers, and run code generation if: inputs.docker-container != '' + env: ${{ fromJSON(inputs.docker-compose-env) }} run: | docker compose up ${{ inputs.docker-container }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/