Skip to content

Commit 84231f1

Browse files
authored
✨ QoL improvements for MQT Core autoupdate (#9)
* ⏪ always use the GitHub token * 📝 rework PR description * 🎨 add `.editorconfig` file * ✨ implement #7 * 🔧 make input optional
1 parent 61f5b12 commit 84231f1

File tree

2 files changed

+88
-31
lines changed

2 files changed

+88
-31
lines changed

.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.{py,pyi}]
12+
indent_size = 4
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
17+
[{*.{cmake,cmake.in},CMakeLists.txt}]
18+
max_line_length = 100
+70-31
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
name: ⬆️ Update MQT Core
22
on:
33
workflow_call:
4-
secrets:
5-
token:
6-
description: |
7-
Personal Access Token (PAT) with `repo` scope.
8-
You can pass the `github.token` provided by GitHub Actions,
9-
which does not have these permissions and, hence, cannot
10-
trigger workflows in the PRs created by this workflow.
11-
As a workaround, such a PR can be closed and re-opened
12-
by a maintainer to trigger the PR workflows.
13-
required: true
14-
4+
inputs:
5+
update-to-head:
6+
description: "Whether to update to the latest commit on the main branch or the latest release"
7+
default: false
8+
type: boolean
9+
required: false
1510
jobs:
1611
update-mqt-core:
1712
name: ⬆️ Update MQT Core
@@ -41,8 +36,7 @@ jobs:
4136
echo "Parsed revision: $revision"
4237
echo "version=$version" >> $GITHUB_OUTPUT
4338
echo "revision=$revision" >> $GITHUB_OUTPUT
44-
# Query the latest tag of mqt-core and its commit SHA via the GitHub API
45-
# Use {github.token} to authenticate with the GitHub API.
39+
# Query the latest tag of mqt-core via the GitHub API (using the GitHub token for authentication).
4640
- name: Get latest release of MQT Core
4741
id: get-latest-release
4842
run: |
@@ -54,56 +48,101 @@ jobs:
5448
echo "tag=$tag"
5549
echo "latest_version=$latest_version"
5650
echo "latest_version=$latest_version" >> $GITHUB_OUTPUT
51+
# Query the commit SHA of the latest tag of mqt-core via the GitHub API (using the GitHub token for authentication).
52+
- name: Get the commit SHA of the latest tag of MQT Core
53+
id: get-latest-tag-sha
54+
run: |
5755
echo "Querying the tags of MQT Core..."
5856
tags=$(curl -s -H "Authorization: token ${{ github.token }}" https://api.github.com/repos/cda-tum/mqt-core/tags)
5957
echo "tags=$tags"
60-
latest_commit=$(echo $tags | jq -r '.[0].commit.sha')
61-
echo "latest_commit=$latest_commit"
62-
echo "latest_commit=$latest_commit" >> $GITHUB_OUTPUT
58+
latest_tag_sha=$(echo $tags | jq -r '.[0].commit.sha')
59+
echo "latest_tag_sha=$latest_tag_sha"
60+
echo "latest_tag_sha=$latest_tag_sha" >> $GITHUB_OUTPUT
61+
# Query the latest commit of the main branch of mqt-core via the GitHub API (using the GitHub token for authentication).
62+
- name: Get the latest commit of the main branch of MQT Core
63+
id: get-latest-commit
64+
run: |
65+
echo "Querying the latest commit of the main branch of MQT Core..."
66+
latest_commit=$(curl -s -H "Authorization: token ${{ github.token }}" https://api.github.com/repos/cda-tum/mqt-core/commits/main)
67+
latest_commit_sha=$(echo $latest_commit | jq -r '.sha')
68+
echo "latest_commit_sha=$latest_commit_sha"
69+
echo "latest_commit_sha=$latest_commit_sha" >> $GITHUB_OUTPUT
6370
# Install the `semver` tool for making semantic version comparisons.
6471
- name: Install semver
6572
run: |
6673
wget -O /usr/local/bin/semver \
6774
https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
6875
chmod +x /usr/local/bin/semver
6976
# Compare the used version with the latest version based on SemVer.
70-
# If the latest version is newer or the version is the same, but the revision
71-
# is different, set the output to update MQT Core.
77+
# Indicate to update MQT Core, whenever
78+
# - the user wants to update to the latest commit on the main branch and the used revision is different, or
79+
# - the latest version is newer than the used version, or
80+
# - the latest version is the same as the used version, but its tag has a different commit SHA than the used revision.
7281
- name: Compare versions
7382
id: compare-versions
7483
run: |
75-
if semver compare ${{ steps.get-used-version.outputs.version }} ${{ steps.get-latest-release.outputs.latest_version }} < 0; then
76-
update=true
77-
elif [ ${{ steps.get-used-version.outputs.version }} = ${{ steps.get-latest-release.outputs.latest_version }} ] && [ ${{ steps.get-used-version.outputs.revision }} != ${{ steps.get-latest-release.outputs.latest_commit }} ]; then
78-
update=true
84+
if [ ${{ inputs.update-to-head }} = true ]
85+
if [ ${{ steps.get-used-version.outputs.revision }} != ${{ steps.get-latest-commit.outputs.latest_commit_sha }} ]; then
86+
update=true
87+
else
88+
update=false
89+
fi
7990
else
80-
update=false
91+
if semver compare ${{ steps.get-used-version.outputs.version }} ${{ steps.get-latest-release.outputs.latest_version }} < 0; then
92+
update=true
93+
elif [ ${{ steps.get-used-version.outputs.version }} = ${{ steps.get-latest-release.outputs.latest_version }} ] && [ ${{ steps.get-used-version.outputs.revision }} != ${{ steps.get-latest-tag-sha.outputs.latest_tag_sha }} ]; then
94+
update=true
95+
else
96+
update=false
97+
fi
8198
fi
8299
echo "update=$update"
83100
echo "update=$update" >> $GITHUB_OUTPUT
101+
# If an update should be performed, properly set the new version and revision based on the update type.
102+
# If the user wants to update to the latest commit on the main branch, set the revision to the latest commit SHA,
103+
# and if the latest commit SHA is different from the latest tag SHA, use the semver tool to increment the patch
104+
# version. Otherwise, set the version to the latest version. If the user wants to update to the latest release,
105+
# set the version to the latest version and the revision to the latest tag SHA.
106+
- name: Determine new version and revision
107+
if: steps.compare-versions.outputs.update == 'true'
108+
id: determine-new-version-and-revision
109+
run: |
110+
if [ ${{ inputs.update-to-head }} = true ]; then
111+
if [ ${{ steps.get-latest-commit.outputs.latest_commit_sha }} != ${{ steps.get-latest-tag-sha.outputs.latest_tag_sha }} ]; then
112+
new_version=$(semver -i patch ${{ steps.get-used-version.outputs.version }})
113+
else
114+
new_version=${{ steps.get-latest-release.outputs.latest_version }}
115+
fi
116+
new_revision=${{ steps.get-latest-commit.outputs.latest_commit_sha }}
117+
else
118+
new_version=${{ steps.get-latest-release.outputs.latest_version }}
119+
new_revision=${{ steps.get-latest-tag-sha.outputs.latest_tag_sha }}
120+
fi
121+
echo "new_version=$new_version"
122+
echo "new_revision=$new_revision"
123+
echo "new_version=$new_version" >> $GITHUB_OUTPUT
124+
echo "new_revision=$new_revision" >> $GITHUB_OUTPUT
84125
# Update the MQT Core version and revision in the `cmake/ExternalDependencies.cmake` file.
85126
- name: Update MQT Core version and revision
86127
id: update-version
87128
if: steps.compare-versions.outputs.update == 'true'
88129
run: |
89-
sed -i 's/set(MQT_CORE_VERSION.*/set(MQT_CORE_VERSION ${{ steps.get-latest-release.outputs.latest_version }}/' cmake/ExternalDependencies.cmake
90-
sed -i 's/set(MQT_CORE_REV.*/set(MQT_CORE_REV "${{ steps.get-latest-release.outputs.latest_commit }}"/' cmake/ExternalDependencies.cmake
130+
sed -i 's/set(MQT_CORE_VERSION.*/set(MQT_CORE_VERSION ${{ steps.detemine-new-version-and-revision.outputs.new_version }}/' cmake/ExternalDependencies.cmake
131+
sed -i 's/set(MQT_CORE_REV.*/set(MQT_CORE_REV "${{ steps.detemine-new-version-and-revision.outputs.new_revision }}"' cmake/ExternalDependencies.cmake
91132
git diff
92133
# Create a pull request to merge the changes into the main branch.
93134
- name: Create pull request
94135
id: create-pull-request
95136
if: steps.compare-versions.outputs.update == 'true'
96137
uses: peter-evans/create-pull-request@v6
97138
with:
98-
token: ${{ secrets.token }}
139+
token: ${{ github.token }}
99140
commit-message: "⬆️ Update `cda-tum/mqt-core`"
100141
title: "⬆️ Update `cda-tum/mqt-core`"
101142
body: |
102-
This pull request updates [MQT Core](https://github.com/cda-tum/mqt-core)
103-
- from cda-tum/mqt-core@${{ steps.get-used-version.outputs.revision }} (version v${{ steps.get-used-version.outputs.version }})
104-
- to cda-tum/mqt-core@${{ steps.get-latest-release.outputs.latest_commit }} (version v${{ steps.get-latest-release.outputs.latest_version }}).
143+
This pull request updates the https://github.com/cda-tum/mqt-core dependency from cda-tum/mqt-core@${{ steps.get-used-version.outputs.revision }} (version v${{ steps.get-used-version.outputs.version }}) to cda-tum/mqt-core@${{ steps.determine-new-version-and-revision.outputs.new_revision }} (version v${{ steps.determine-new-version-and-revision.outputs.new_version }}).
105144
106-
**Full Changelog**: https://github.com/cda-tum/mqt-core/compare/${{ steps.get-used-version.outputs.revision }}...${{ steps.get-latest-release.outputs.latest_commit }}
107-
branch: "update-mqt-core-${{ steps.get-latest-release.outputs.latest_commit }}"
145+
**Full Changelog**: https://github.com/cda-tum/mqt-core/compare/${{ steps.get-used-version.outputs.revision }}...${{ steps.determine-new-version-and-revision.outputs.new_revision }}
146+
branch: "update-mqt-core-${{ steps.determine-new-version-and-revision.outputs.new_revision }}"
108147
labels: "dependencies,c++"
109148
base: "main"

0 commit comments

Comments
 (0)