1
1
name : ⬆️ Update MQT Core
2
2
on :
3
3
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
15
10
jobs :
16
11
update-mqt-core :
17
12
name : ⬆️ Update MQT Core
41
36
echo "Parsed revision: $revision"
42
37
echo "version=$version" >> $GITHUB_OUTPUT
43
38
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).
46
40
- name : Get latest release of MQT Core
47
41
id : get-latest-release
48
42
run : |
@@ -54,56 +48,101 @@ jobs:
54
48
echo "tag=$tag"
55
49
echo "latest_version=$latest_version"
56
50
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 : |
57
55
echo "Querying the tags of MQT Core..."
58
56
tags=$(curl -s -H "Authorization: token ${{ github.token }}" https://api.github.com/repos/cda-tum/mqt-core/tags)
59
57
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
63
70
# Install the `semver` tool for making semantic version comparisons.
64
71
- name : Install semver
65
72
run : |
66
73
wget -O /usr/local/bin/semver \
67
74
https://raw.githubusercontent.com/fsaintjacques/semver-tool/master/src/semver
68
75
chmod +x /usr/local/bin/semver
69
76
# 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.
72
81
- name : Compare versions
73
82
id : compare-versions
74
83
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
79
90
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
81
98
fi
82
99
echo "update=$update"
83
100
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
84
125
# Update the MQT Core version and revision in the `cmake/ExternalDependencies.cmake` file.
85
126
- name : Update MQT Core version and revision
86
127
id : update-version
87
128
if : steps.compare-versions.outputs.update == 'true'
88
129
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
91
132
git diff
92
133
# Create a pull request to merge the changes into the main branch.
93
134
- name : Create pull request
94
135
id : create-pull-request
95
136
if : steps.compare-versions.outputs.update == 'true'
96
137
uses : peter-evans/create-pull-request@v6
97
138
with :
98
- token : ${{ secrets .token }}
139
+ token : ${{ github .token }}
99
140
commit-message : " ⬆️ Update `cda-tum/mqt-core`"
100
141
title : " ⬆️ Update `cda-tum/mqt-core`"
101
142
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 }}).
105
144
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 }}"
108
147
labels : " dependencies,c++"
109
148
base : " main"
0 commit comments