-
Notifications
You must be signed in to change notification settings - Fork 111
CI: Add support of release branches #6589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
oitel
wants to merge
1
commit into
master
Choose a base branch
from
feature/ci_release_branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,16 @@ | ||
| name: Build Pip Wheels | ||
|
|
||
| # When ran from the github UI, we build the target commit exactly. | ||
| # When ran on release, we use the latest tagged commit in the `master` branch. | ||
| # This doesn't run directly on pull request, because it's impossible to disable the whole file | ||
| # with a single condition (specific label present). Because of that, we conditionally run this from a separate `.yml` file. | ||
|
|
||
| on: | ||
| release: | ||
| types: [ published ] | ||
|
Comment on lines
-9
to
-10
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. who runs it? |
||
| # This is the manual run from the UI. | ||
| workflow_dispatch: | ||
| inputs: | ||
| vcpkg_docker_image_tag: | ||
| # Empty string means the same thing as "latest", but we use an empty string here to ensure this works, | ||
| # because `types: [published]` can't have any inputs, so there we are forced to use an empty string, so it needs to work. | ||
| # because a `workflow_call` from a release path can't pass inputs, so it needs to work. | ||
| default: "" | ||
| required: false | ||
| type: string | ||
|
|
@@ -95,7 +92,7 @@ jobs: | |
| version_tag: ${{ steps.get-latest-tag.outputs.tag }} | ||
| build-matrix: ${{ steps.build-matrix.outputs.matrix }} | ||
| test-matrix: ${{ steps.test-matrix.outputs.matrix }} | ||
| publish_prod: ${{ github.event_name == 'release' || inputs.publish == 'publish-prod' }} | ||
| publish_prod: ${{ inputs.publish == 'publish-prod' }} | ||
| publish_test: ${{ inputs.publish == 'publish-test' }} | ||
| build_ref: ${{ inputs.ref || steps.get-latest-tag.outputs.tag }} | ||
| release_tag: ${{ inputs.release_tag || steps.release-for-ref.outputs.tag }} | ||
|
|
@@ -107,7 +104,7 @@ jobs: | |
| # Disabling this with an `if:` results in `steps.get-latest-tag.outputs.tag` being empty. | ||
| # Passing that to `ref:` makes it default to the current commit, which is exactly what we need. | ||
| - uses: actions-ecosystem/action-get-latest-tag@v1 | ||
| if: ${{ github.event_name == 'release' || inputs.publish == 'publish-prod' }} | ||
| if: ${{ inputs.publish == 'publish-prod' }} | ||
| id: get-latest-tag | ||
|
|
||
| # Attach to a release that already exists for this ref; never create one. No match leaves the | ||
|
|
@@ -952,11 +949,6 @@ jobs: | |
| - name: Upload to TestPyPI | ||
| run: twine upload --repository-url https://test.pypi.org/legacy/ ./meshlib*.whl -u __token__ -p ${{ secrets.TEST_PYPI_TOKEN }} --skip-existing | ||
|
|
||
| post-release-test: | ||
| if: ${{ needs.setup.outputs.publish_prod == 'true' }} | ||
| needs: [setup, upload-to-release] | ||
| uses: MeshInspector/MeshLib/.github/workflows/release-tests.yml@master | ||
|
|
||
| delete-artifacts: | ||
| timeout-minutes: 5 | ||
| runs-on: ubuntu-latest | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| name: Publish documentation | ||
|
|
||
| on: | ||
| release: | ||
| types: [ released ] | ||
| workflow_dispatch: | ||
| inputs: | ||
| release_tag: | ||
| description: Tag of the release to publish the documentation of | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
| actions: read # list workflow runs, and download artifacts from another run | ||
|
|
||
| jobs: | ||
| # The binding artifacts live on the build run, not on the release, and | ||
| # `download-artifact` only reaches another run by id. | ||
| find-build-run: | ||
| timeout-minutes: 5 | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| run_id: ${{ steps.find.outputs.run_id }} | ||
| steps: | ||
| - name: Find the build that produced this release | ||
| id: find | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| TAG: ${{ inputs.release_tag || github.event.release.tag_name }} | ||
| run: | | ||
| set -euo pipefail | ||
| sha=$(gh api "repos/${GITHUB_REPOSITORY}/commits/${TAG}" --jq .sha) | ||
| run_id=$( | ||
| gh api "repos/${GITHUB_REPOSITORY}/actions/workflows/build-test-distribute.yml/runs?head_sha=${sha}&status=success" \ | ||
| --jq '[ .workflow_runs[] | .id ] | max // empty' | ||
| ) | ||
| [ -n "${run_id}" ] || { echo "no successful build for ${TAG} (${sha})" >&2 ; exit 1 ; } | ||
| echo "${TAG} -> ${sha} -> run ${run_id}" | ||
| echo "run_id=${run_id}" >> $GITHUB_OUTPUT | ||
|
|
||
| update-documentation: | ||
| needs: find-build-run | ||
| uses: ./.github/workflows/update-docs.yml | ||
| with: | ||
| output_folder: MeshLib | ||
| run_id: ${{ needs.find-build-run.outputs.run_id }} | ||
| secrets: inherit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Publish to PyPI | ||
|
|
||
| on: | ||
| release: | ||
| types: [ released ] | ||
| workflow_dispatch: | ||
| inputs: | ||
| release_tag: | ||
| description: Tag of the release whose wheels to publish | ||
| required: true | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| publish: | ||
| timeout-minutes: 30 | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # The wheels attached to the release are the ones that were built and | ||
| # tested on that commit; nothing is rebuilt here. | ||
| - name: Download wheels from the release | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| TAG: ${{ inputs.release_tag || github.event.release.tag_name }} | ||
| run: | | ||
| gh release download "${TAG}" --repo "${GITHUB_REPOSITORY}" --pattern '*.whl' --clobber | ||
| ls -1 meshlib*.whl | ||
|
|
||
| - name: Install twine | ||
| run: python3 -m pip install --upgrade pip twine packaging | ||
|
|
||
| - name: Upload to Production PyPi | ||
| run: twine upload ./meshlib*.whl -u __token__ -p ${{ secrets.PYPI_MESHINSPECTOR_TOKEN }} --skip-existing | ||
|
|
||
| post-release-test: | ||
| needs: publish | ||
| uses: ./.github/workflows/release-tests.yml | ||
| with: | ||
| version_tag: ${{ inputs.release_tag || github.event.release.tag_name }} | ||
| secrets: inherit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| name: Publish release | ||
|
|
||
| # Run it from the release branch whose newest draft should be published. | ||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| publish-release: | ||
| timeout-minutes: 10 | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Publish | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| BRANCH: ${{ github.ref_name }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| series=$(echo "${BRANCH}" | sed -n 's|^release/\([0-9]\{1,\}\.[0-9]\{1,\}\).*|\1|p') | ||
| [ -n "${series}" ] || { echo "expected release/<major>.<minor>[...], got '${BRANCH}'" >&2 ; exit 1 ; } | ||
|
|
||
| gh api "repos/${GITHUB_REPOSITORY}/releases" --paginate > releases.json | ||
|
|
||
| # A draft has no git tag, so GET /releases/tags/<tag> cannot find it. | ||
| # The branch's drafts are the -rc ones on its own major.minor series. | ||
| drafts=$( | ||
| jq -r --arg p "v${series}." ' | ||
| .[] | select(.draft and (.tag_name | startswith($p) and endswith("-rc"))) | ||
| | "\(.tag_name)\t\(.id)\t\(.target_commitish)"' releases.json | ||
| ) | ||
| [ -n "${drafts}" ] || { echo "no -rc draft on ${BRANCH}" >&2 ; exit 1 ; } | ||
| IFS=$'\t' read -r draft_tag release_id target \ | ||
| <<< "$(printf '%s\n' "${drafts}" | sort -V | tail -n1)" | ||
|
|
||
| version="${draft_tag%-rc}" # v3.1.4.7-rc -> v3.1.4.7 | ||
| baseline="${version%.*}" # v3.1.4.7 -> v3.1.4 | ||
| echo "${version}" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' \ | ||
| || { echo "unexpected version shape ${version}" >&2 ; exit 1 ; } | ||
|
|
||
| sha=$(gh api "repos/${GITHUB_REPOSITORY}/commits/${target}" --jq .sha) | ||
|
|
||
| # Guards against tagging a commit the draft was never built from. | ||
| status=$(gh api "repos/${GITHUB_REPOSITORY}/compare/${BRANCH}...${sha}" --jq .status) | ||
| case "${status}" in | ||
| identical|behind) ;; | ||
| *) echo "${draft_tag} targets ${sha}, which is ${status} ${BRANCH}" >&2 ; exit 1 ;; | ||
| esac | ||
|
|
||
| # The baseline tag goes on before publishing: publishing fires the | ||
| # release workflows, and they must not see a half-tagged release. | ||
| if existing=$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${baseline}" --jq .object.sha 2>/dev/null) ; then | ||
| [ "${existing}" = "${sha}" ] \ | ||
| || { echo "${baseline} already exists on ${existing}, not ${sha}" >&2 ; exit 1 ; } | ||
| echo "${baseline} already points at ${sha}" | ||
| else | ||
| gh api -X POST "repos/${GITHUB_REPOSITORY}/git/refs" \ | ||
| -f "ref=refs/tags/${baseline}" -f "sha=${sha}" | ||
| fi | ||
|
|
||
| # Notes cover this patch only, so diff against the previous release on | ||
| # the same line rather than letting GitHub pick one across lines. The | ||
| # release being published is still a draft, so it is not a candidate. | ||
| previous=$( | ||
| jq -r --arg p "v${series}." '.[] | select( ( .draft | not ) and ( .tag_name | startswith($p) ) ) | .tag_name' \ | ||
| releases.json | sort -V | tail -n1 | ||
| ) | ||
| notes=$( | ||
| gh api -X POST "repos/${GITHUB_REPOSITORY}/releases/generate-notes" \ | ||
| -f "tag_name=${version}" -f "target_commitish=${sha}" \ | ||
| ${previous:+-f "previous_tag_name=${previous}"} --jq .body | ||
| ) || notes="" | ||
| echo "notes generated against ${previous:-<no previous release>}" | ||
|
|
||
| # Renaming the tag drops the -rc; publishing creates it on ${sha}. | ||
| # %details_after_publish% is left for release-body-update.yml. | ||
| if [ -n "${notes}" ] ; then | ||
| gh api -X PATCH "repos/${GITHUB_REPOSITORY}/releases/${release_id}" \ | ||
| -f "tag_name=${version}" -F draft=false \ | ||
| -f "body=${notes}"$'\n\n'"%details_after_publish%" | ||
| else | ||
| gh api -X PATCH "repos/${GITHUB_REPOSITORY}/releases/${release_id}" \ | ||
| -f "tag_name=${version}" -F draft=false | ||
| fi | ||
|
|
||
| echo "published ${version} from ${BRANCH}, baseline ${baseline} -> ${sha}" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mb make the rule more strict?