@@ -109,3 +109,116 @@ jobs:
109109 else
110110 echo "No metadata changes detected"
111111 fi
112+ name : Update Metadata
113+
114+ on :
115+ push :
116+ workflow_dispatch :
117+
118+ # Prevent infinite loops when workflow commits changes
119+ concurrency :
120+ group : ${{ github.workflow }}-${{ github.ref }}
121+ cancel-in-progress : true
122+
123+ jobs :
124+ update-metadata :
125+ runs-on : ubuntu-latest
126+ # Need write permission to push changes
127+ permissions :
128+ contents : write
129+ steps :
130+ - name : Checkout repository
131+ uses : actions/checkout@v4
132+ with :
133+ ref : ${{ github.ref }}
134+ fetch-depth : 0
135+
136+ - name : Extract version from tag (if triggered by tag)
137+ id : extract_version
138+ run : |
139+ if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
140+ TAG_NAME=${GITHUB_REF#refs/tags/}
141+ # Remove 'v' prefix if present (v1.0.0 -> 1.0.0)
142+ VERSION=${TAG_NAME#v}
143+ echo "version=$VERSION" >> $GITHUB_OUTPUT
144+ echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
145+ echo "is_tag=true" >> $GITHUB_OUTPUT
146+ echo "Triggered by version tag: $TAG_NAME (version: $VERSION)"
147+ else
148+ echo "is_tag=false" >> $GITHUB_OUTPUT
149+ echo "Triggered by regular push to: $GITHUB_REF"
150+ fi
151+
152+ - name : Set up Python
153+ uses : actions/setup-python@v5
154+ with :
155+ python-version-file : ' .python-version'
156+ cache : pip
157+
158+ - name : Install dependencies
159+ run : |
160+ python -m pip install --upgrade pip
161+ pip install pyyaml rdflib
162+
163+ - name : Update version metadata (if triggered by tag)
164+ if : steps.extract_version.outputs.is_tag == 'true'
165+ env :
166+ TAG_VERSION : ${{ steps.extract_version.outputs.version }}
167+ run : |
168+ python -m quadriga.metadata.update_version_from_tag
169+
170+ - name : Update metadata files
171+ env :
172+ PYTHONHASHSEED : 0
173+ run : python -m quadriga.metadata.run_all
174+
175+ - name : Check if files changed
176+ id : check_changes
177+ run : |
178+ if git diff --quiet metadata.yml && git diff --quiet CITATION.bib && git diff --quiet CITATION.cff && git diff --quiet .zenodo.json && git diff --quiet metadata.jsonld && git diff --quiet metadata.rdf; then
179+ echo "changes_detected=false" >> $GITHUB_OUTPUT
180+ else
181+ echo "changes_detected=true" >> $GITHUB_OUTPUT
182+ fi
183+
184+ - name : Commit changes (regular push)
185+ if : steps.check_changes.outputs.changes_detected == 'true' && steps.extract_version.outputs.is_tag == 'false'
186+ run : |
187+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
188+ git config --local user.name "github-actions[bot]"
189+ git add metadata.yml CITATION.bib CITATION.cff .zenodo.json metadata.jsonld metadata.rdf
190+ git commit -m "[Automated] Update metadata files"
191+ git push
192+
193+ - name : Commit changes and move tag (tag-triggered)
194+ if : steps.check_changes.outputs.changes_detected == 'true' && steps.extract_version.outputs.is_tag == 'true'
195+ run : |
196+ # Configure git
197+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
198+ git config --local user.name "github-actions[bot]"
199+
200+ # Commit the metadata changes
201+ git add metadata.yml CITATION.bib CITATION.cff .zenodo.json metadata.jsonld metadata.rdf
202+ git commit -m "[Automated] Update metadata for version ${{ steps.extract_version.outputs.version }}"
203+
204+ # Delete the old tag (locally and remotely)
205+ git tag -d ${{ steps.extract_version.outputs.tag_name }}
206+ git push origin :refs/tags/${{ steps.extract_version.outputs.tag_name }}
207+
208+ # Create new tag at the current commit (with updated metadata)
209+ git tag ${{ steps.extract_version.outputs.tag_name }}
210+
211+ # Push the changes and the new tag
212+ git push origin HEAD:main
213+ git push origin ${{ steps.extract_version.outputs.tag_name }}
214+
215+ echo "Tag ${{ steps.extract_version.outputs.tag_name }} moved to commit with updated metadata"
216+
217+ - name : No changes needed
218+ if : steps.check_changes.outputs.changes_detected == 'false'
219+ run : |
220+ if [[ "${{ steps.extract_version.outputs.is_tag }}" == "true" ]]; then
221+ echo "Metadata already matches the tag version - no changes needed"
222+ else
223+ echo "No metadata changes detected"
224+ fi
0 commit comments