-
Notifications
You must be signed in to change notification settings - Fork 19
88 lines (73 loc) · 3.04 KB
/
extend_user_cff.yml
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
name: create-pr-to-add-user-to-usercff
on:
workflow_dispatch:
issues:
types: [opened, labeled]
permissions:
contents: write
pull-requests: write
jobs:
create-pr-to-add-new-user:
if: contains(join(github.event.issue.labels.*.name, ','), 'user')
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# checkout to develop branch of repo
ref: develop
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Extract issue details
id: extract_details
run: |
echo "Extracting issue details..."
ISSUE_BODY="${{ github.event.issue.body }}"
echo "Issue body content:"
echo "$ISSUE_BODY"
# Extract information
FAMILY_NAMES=$(echo "$ISSUE_BODY" | grep '^family-names:' | sed 's/family-names: //')
GIVEN_NAMES=$(echo "$ISSUE_BODY" | grep '^given-names:' | sed 's/given-names: //')
ALIAS=$(echo "$ISSUE_BODY" | grep '^alias:' | sed 's/alias: //')
AFFILIATION=$(echo "$ISSUE_BODY" | grep '^affiliation:' | sed 's/affiliation: //')
ORCID=$(echo "$ISSUE_BODY" | grep '^orcid:' | sed 's/orcid: //')
# Delete new lines and add to env variables
echo "FAMILY_NAMES=$(echo -n $FAMILY_NAMES | tr -d '\n')" >> $GITHUB_ENV
echo "GIVEN_NAMES=$(echo -n $GIVEN_NAMES | tr -d '\n')" >> $GITHUB_ENV
echo "ALIAS=$(echo -n $ALIAS | tr -d '\n')" >> $GITHUB_ENV
echo "AFFILIATION=$(echo -n $AFFILIATION | tr -d '\n')" >> $GITHUB_ENV
echo "ORCID=$(echo -n $ORCID | tr -d '\n')" >> $GITHUB_ENV
- name: Debug extracted values
run: |
echo "Family Names: ${{env.FAMILY_NAMES}}"
echo "Given Names: ${{env.GIVEN_NAMES}}"
echo "Alias: ${{env.ALIAS}}"
echo "Affiliation: ${{env.AFFILIATION}}"
echo "ORCID: ${{env.ORCID}}"
- name: Update USERS.cff
run: |
# double quotes are not added, due to formatting hell. Double quotes will cause the creation of additional unwanted new lines, even when checked out as \"
tee -a USERS.cff <<EOF
- family-names: ${{env.FAMILY_NAMES}}
given-names: ${{env.GIVEN_NAMES}}
alias: ${{env.ALIAS}}
affiliation: ${{env.AFFILIATION}}
orcid: ${{env.ORCID}}
EOF
- name: Print updated USERS.cff
run: cat USERS.cff
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
base: develop
head: workflow-${{ github.event.issue.number }}-update-users-cff
branch: workflow-${{ github.event.issue.number }}-update-users-cff
title: 'Update USERS.cff with new user information'
commit-message: |
Add new user to USERS.cff
body: |
This pull request updates the USERS.cff file with new user information extracted from issue #${{ github.event.issue.number }}
Closes #${{ github.event.issue.number }}
Many thanks @${{ github.actor }}!