Register DOIs for new Posts #63779
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Register DOIs for new Posts | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "*/10 * * * *" | |
jobs: | |
register: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ">=1.23" | |
- name: Download most recent unregistered post | |
run: | | |
mkdir -p upload | |
curl https://api.rogue-scholar.org/posts/unregistered?per_page=1 > upload/posts.json | |
- name: Set number of unregistered posts as variable | |
id: current_number | |
run: | | |
echo "NUMBER=$(jq '."total-results"' upload/posts.json)" >> $GITHUB_OUTPUT | |
- name: Install commonmeta | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
go install github.com/front-matter/[email protected] | |
commonmeta version | |
- name: Set current date as variable | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
echo "NOW=$(date +'%s')" >> $GITHUB_OUTPUT | |
id: current_date | |
- name: Set blog community id as variable | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
echo "ID=$(jq -r '.items[0].blog.community_id' upload/posts.json)" >> $GITHUB_OUTPUT | |
id: community | |
- name: Convert posts to commonmeta and autogenerate dois based on prefix | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
commonmeta list upload/posts.json -f jsonfeed > upload/commonmeta.json | |
- name: Convert commonmeta to crossref xml | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
commonmeta list upload/commonmeta.json -f commonmeta --depositor "${{ secrets.CROSSREF_DEPOSITOR_NAME }}" --email "${{ secrets.CROSSREF_DEPOSITOR_EMAIL }}" --registrant "${{ secrets.CROSSREF_REGISTRANT }}" -t crossrefxml > upload/${{ steps.current_date.outputs.NOW }} | |
- name: Update content via Crossref API | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
curl -X POST https://doi.crossref.org/servlet/deposit -F "operation=doMDUpload" -F "login_id=${{ secrets.CROSSREF_USERNAME_WITH_ROLE }}" -F "login_passwd=${{ secrets.CROSSREF_PASSWORD }}" -F "fname=@upload/${{ steps.current_date.outputs.NOW }}" | |
- name: Set post uuid, doi and blog slug as variables | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
echo "UUID=$(jq -r '[.[] | .identifiers | .[1].identifier] | first' upload/commonmeta.json)" >> $GITHUB_OUTPUT | |
echo "DOI=$(jq -rc '[.[] | .id] | first' upload/commonmeta.json)" >> $GITHUB_OUTPUT | |
echo "SLUG=$(jq -r '[.[] | .container.identifier] | first' upload/commonmeta.json)" >> $GITHUB_OUTPUT | |
id: current_post | |
- name: Convert commonmeta to inveniordm | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
commonmeta list upload/commonmeta.json -f commonmeta -t inveniordm > upload/inveniordm_list.json | |
cat upload/inveniordm_list.json | jq -r '.[0]' > upload/inveniordm.json | |
- name: create InvenioRDM draft record | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
curl -X POST https://rogue-scholar.org/api/records -H "Authorization: Bearer ${{ secrets.INVENIORDM_TOKEN }}" -H "Content-Type: application/json" -d @upload/inveniordm.json > upload/response.json | |
echo "RID=$(jq -r '.id' upload/response.json)" >> $GITHUB_OUTPUT | |
id: inveniordm | |
- name: publish InvenioRDM draft record | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
curl -X POST https://rogue-scholar.org/api/records/${{ steps.inveniordm.outputs.RID }}/draft/actions/publish -H "Authorization: Bearer ${{ secrets.INVENIORDM_TOKEN }}" -H "Content-Type: application/json" | |
- name: Add post to blog community | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
curl -X POST https://rogue-scholar.org/api/records/${{ steps.inveniordm.outputs.RID }}/communities -H "Authorization: Bearer ${{ secrets.INVENIORDM_TOKEN }}" -H "Content-Type: application/json" -d '{ "communities": [{"id": "${{ steps.community.outputs.ID }}"}] }' | |
- name: update Rogue Scholar post | |
if: ${{ fromJSON(steps.current_number.outputs.NUMBER) > 0 }} | |
run: | | |
curl -X PATCH https://db.rogue-scholar.org/rest/v1/posts?id=eq.${{ steps.current_post.outputs.UUID }} -H "apikey: ${{ secrets.SUPABASE_KEY }}" -H "Authorization: Bearer ${{ secrets.SUPABASE_KEY }}" -H "Content-Type: application/json" -H "Prefer: return=minimal" -d '{ "doi": "${{ steps.current_post.outputs.DOI }}", "rid": "${{ steps.inveniordm.outputs.RID }}", "indexed_at": "${{ steps.current_date.outputs.NOW }}", "indexed": true }' | |
- name: Update Front Matter blog | |
if: steps.current_post.outputs.SLUG == '2749-9952' | |
run: commonmeta update-ghost-post --api-key ${{ secrets.GHOST_ADMIN_API_KEY }} --api-url ${{ secrets.GHOST_ADMIN_API_URL }} ${{ steps.current_post.outputs.UUID }} | |
- name: Update Upstream blog | |
if: steps.current_post.outputs.SLUG == 'https://rogue-scholar.org/blogs/upstream/' | |
run: commonmeta update-ghost-post --api-key ${{ secrets.UPSTREAM_ADMIN_API_KEY }} --api-url ${{ secrets.UPSTREAM_ADMIN_API_URL }} ${{ secrets.UPSTREAM_ADMIN_API_URL }} ${{ steps.current_post.outputs.UUID }} |