-
Notifications
You must be signed in to change notification settings - Fork 20
116 lines (100 loc) · 4.1 KB
/
citation-updater.yaml
File metadata and controls
116 lines (100 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Zero-config modular workflow for updating CITATION.cff upon new releases.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
name: CITATION.cff updater
run-name: Update CITATION.cff for new release
on:
release:
types: [published]
# Allow manual invocation.
workflow_dispatch:
inputs:
use_tag:
description: 'Value of tag_name to use:'
type: string
required: true
use_date:
description: 'Value of published_date to use:'
type: string
required: true
# Declare default permissions as read only.
permissions: read-all
# Cancel any previously-started but still active runs on the same branch.
concurrency:
cancel-in-progress: true
group: ${{github.workflow}}-${{github.event.pull_request.number||github.ref}}
jobs:
update-citation-cff:
name: Update CITATION.cff file
runs-on: ubuntu-24.04
timeout-minutes: 5
permissions:
contents: write
env:
version_tag: ${{inputs.use_tag || github.event.release.tag_name}}
pub_date: ${{inputs.use_date || github.event.release.published_at}}
steps:
- if: ${{!env.version_tag || !env.pub_date}}
name: Quit if the release tag or publication date is empty
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
with:
script: |
core.setFailed('The release version and/or date could not be read')
- name: Check out a copy of the git repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4.2.2
- name: Verify that this repo has a CITATION.cff file
id: check
run: |
[[ -f CITATION.cff ]] && have_cff=true || have_cff=false
echo "has_cff_file=$have_cff" >> "$GITHUB_OUTPUT"
- if: steps.check.outputs.has_cff_file == 'false'
name: Quit if there is no CITATION.cff file
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
with:
script: |
core.setFailed('Could not find a CITATION.cff file')
- name: Update the CITATION.cff file
id: update
run: |
echo "::group::CITATION.cff file before update"
cat CITATION.cff
echo "::endgroup::"
set -x
version="${{env.version_tag}}"
version="${version#v}"
date=$(date -u -d "${{env.pub_date}}" +"%Y-%m-%d")
sed -i "s/^version:.*$/version: '$version'/" CITATION.cff
sed -i "s/^date-released:.*$/date-released: $date/" CITATION.cff
# Sanity-check that the result looks valid.
success=true
yamllint CITATION.cff > /dev/null 2>&1 || success=false
written_version=$(yq -r .version CITATION.cff)
[[ "$version" == "$written_version" ]] || success=false
echo "success=$success" >> "$GITHUB_OUTPUT"
echo "::group::CITATION.cff file after update"
cat CITATION.cff
echo "::endgroup::"
- if: steps.update.outputs.success == 'false'
name: Quit if CITATION.cff update failed
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
with:
script: |
core.setFailed('CITATION.cff update failed or the file is not valid')
- if: steps.update.outputs.success == 'true'
name: Commit the updated CITATION.cff back to the repo
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9
with:
add: CITATION.cff
message: 'Update version and date in CITATION.cff file'