Repository navigation
145 lines (125 loc) · 5.11 KB
/
Copy pathrelease-with-doi.yml
File metadata and controls
145 lines (125 loc) · 5.11 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Create Release and Update DOI
on:
push:
branches:
- main
paths-ignore:
- 'src/data/config.js'
- 'scripts/updatePdfPage.js'
permissions:
contents: write # Required for creating releases
jobs:
check-if-skip:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- run: echo "Proceeding with workflow"
outputs:
should_continue: "true"
check-and-release:
needs: check-if-skip
if: needs.check-if-skip.outputs.should_continue == 'true'
runs-on: ubuntu-latest
permissions:
contents: write # Required for creating releases
outputs:
new_doi: ${{ steps.get_doi.outputs.doi }}
release_created: ${{ steps.release_status.outputs.release_created }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get date for release
id: date
run: echo "date=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
with:
name: Yourself To Science - ${{ steps.date.outputs.date }}
tag_name: v${{ steps.date.outputs.date }}
draft: false
prerelease: false
files: |
public/yourselftoscience.pdf
public/sitemap.xml
body: |
This release includes:
- Updated resources list
- Enhanced citation information
- Latest content as of ${{ steps.date.outputs.date }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set release created flag
run: echo "release_created=true" >> $GITHUB_OUTPUT
id: release_status
- name: Wait for Zenodo to process
run: |
echo "Waiting for Zenodo to process the new release..."
sleep 60
- name: Wait for and check Zenodo DOI
id: get_doi
run: |
echo "Waiting for and checking Zenodo DOI..."
# Try up to 8 times with 20-second intervals (max 160 seconds total)
for attempt in {1..8}; do
echo "Attempt $attempt of 8..."
# Try community API endpoint
ZENODO_RECORD=$(curl -sL "https://zenodo.org/api/communities/github/records?q=github.repository:yourselftoscience/yourselftoscience.org&sort=mostrecent&size=1")
HITS_COUNT=$(echo $ZENODO_RECORD | jq -r '.hits.total')
if [[ "$HITS_COUNT" != "0" && ! -z "$HITS_COUNT" ]]; then
echo "Found record in Zenodo GitHub community!"
VERSION_DOI=$(echo $ZENODO_RECORD | jq -r '.hits.hits[0].doi // ""')
if [[ -n "$VERSION_DOI" ]]; then
echo "doi=$VERSION_DOI" >> $GITHUB_OUTPUT
echo "Retrieved DOI: $VERSION_DOI"
exit 0
fi
fi
# Try direct DOI query - updated to use the concept DOI
ZENODO_RECORD=$(curl -sL "https://zenodo.org/api/records/15109359")
VERSION_DOI=$(echo $ZENODO_RECORD | jq -r '.doi // ""')
if [[ -n "$VERSION_DOI" ]]; then
echo "Found record via direct DOI query!"
echo "doi=$VERSION_DOI" >> $GITHUB_OUTPUT
echo "Retrieved DOI: $VERSION_DOI"
exit 0
fi
echo "No record found yet. Waiting 20 seconds before next attempt..."
sleep 20
done
# Always ensure we have a DOI (use correct concept DOI as fallback)
VERSION_DOI="10.5281/zenodo.15109359"
echo "doi=$VERSION_DOI" >> $GITHUB_OUTPUT
echo "Using concept DOI: $VERSION_DOI"
- name: Write DOI to file
if: steps.get_doi.outputs.doi
run: |
echo "Writing DOI ${{ steps.get_doi.outputs.doi }} to public/latest_doi.txt"
mkdir -p public
echo "${{ steps.get_doi.outputs.doi }}" > public/latest_doi.txt
- name: Update DOI in config.js
if: steps.get_doi.outputs.doi
run: |
DOI_VALUE="${{ steps.get_doi.outputs.doi }}"
CONFIG_FILE="src/data/config.js"
# Use sed to replace the hardcoded DOI in the config file
sed -i "s/export const latestDoi = '[0-9\.]*\/zenodo\.[0-9]*';/export const latestDoi = '$DOI_VALUE';/" "$CONFIG_FILE"
echo "Updated DOI in $CONFIG_FILE"
- name: Configure Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Commit and push updated files
if: steps.get_doi.outputs.doi
run: |
git add public/latest_doi.txt src/data/config.js
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to DOI files to commit."
else
git commit -m "Update latest DOI [skip ci]"
git push
echo "Committed and pushed updated DOI files."
fi