Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions .github/workflows/release-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,38 @@ jobs:
with:
python-version: '3.11'
architecture: 'x64'
- name: Check labels
id: check-labels
env:
GH_TOKEN: ${{ github.token }}
run: |
pr_number=$(git log -1 --pretty="%s" | sed -n -E "s/.*[(]#([0-9]+)[)]$/\1/p")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sed command concerns me due to its complexity and assumption about the format of the log message. The following may be more robust:

pr_number=$(gh pr list --search "${{ github.sha }}" --state merged --json number --jq '.[0].number')

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. I thought about that option, but I feel it is vulnerable to race condition. The push event that starts this workflow is emitted right after the PR merge to main, ie, after the state flip from OPEN to MERGED. gh pr list --search presumably checks some database and I am not sure it is guaranteed to be up-to-date by the time of the push event. OTOH, the main head must exist in the working repo and for the past 4 years the commit subject line has ended in (#PR_NUMBER) (the first exception being #5196 which might have been a manual push).

In the worst case, when sed pattern does not match, the pr_number is set to an empty string which is handled just as the default no-special-label case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about the potential race condition.

if (( pr_number )) &&
gh pr view --json=labels --jq=".labels[].name" "${pr_number}" |
grep -q -x ci/no-release;
then
echo "The PR has a ci/no-release label - skipping the release"
echo "### Skipped release due to ci/no-release label" >> "${GITHUB_STEP_SUMMARY}"
has_no_release=true
else
has_no_release=false
fi
echo "has_no_release=${has_no_release}" >> "${GITHUB_OUTPUT}"
- name: Install dependencies
if: steps.check-labels.outputs.has_no_release != 'true'
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel twine
- name: Create PyPI config file
if: steps.check-labels.outputs.has_no_release != 'true'
env:
CIRQ_PYPI_TOKEN: ${{ secrets.CIRQ_PYPI_TOKEN }}
CIRQ_TEST_PYPI_TOKEN: ${{ secrets.CIRQ_TEST_PYPI_TOKEN }}
run: |
envsubst < dev_tools/packaging/pypirc_template > $HOME/.pypirc
- name: Build and publish
env:
GH_TOKEN: ${{ github.token }}
if: steps.check-labels.outputs.has_no_release != 'true'
run: |
pr_number=$(git log -1 --pretty="%s" | sed -n -E "s/.*[(]#([0-9]+)[)]$/\1/p")
if (( pr_number )) &&
gh pr view --json=labels --jq=".labels[].name" "${pr_number}" |
grep -q -x ci/no-release;
then
echo "The PR has a ci/no-release label - skipping the release"
echo "### Skipped release due to ci/no-release label" >> ${GITHUB_STEP_SUMMARY}
exit 0
fi
CIRQ_PRE_RELEASE_VERSION=$(dev_tools/packaging/generate-dev-version-id.sh)
if [[ "${CIRQ_PRE_RELEASE_VERSION}" != *.dev* ]]; then
echo "Not a dev version"
Expand All @@ -62,9 +71,9 @@ jobs:
echo "Comparing wheels with the build at previous commit"
if diff -q -r "${out_dir_last}" "${out_dir}"; then
echo "Wheels are identical - skipping the release"
echo "### Skipped identical release" >> ${GITHUB_STEP_SUMMARY}
echo "### Skipped identical release" >> "${GITHUB_STEP_SUMMARY}"
echo "Cirq wheels for ${CIRQ_PRE_RELEASE_VERSION} (${GITHUB_SHA})" \
"are identical to their build at the previous commit." >> ${GITHUB_STEP_SUMMARY}
"are identical to their build at the previous commit." >> "${GITHUB_STEP_SUMMARY}"
exit 0
fi
echo "Deploying dev version '$CIRQ_PRE_RELEASE_VERSION'"
Expand Down
Loading