|
| 1 | +name: Version DOI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*'] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + publish-doi: |
| 12 | + name: Publish Version DOI |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Create release if missing |
| 16 | + env: |
| 17 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 18 | + run: | |
| 19 | + TAG="${{ github.ref_name }}" |
| 20 | + # Create release if it doesn't already exist (e.g., manual tag push) |
| 21 | + gh release view "$TAG" --repo "${{ github.repository }}" > /dev/null 2>&1 || \ |
| 22 | + gh release create "$TAG" --repo "${{ github.repository }}" \ |
| 23 | + --title "$TAG" --notes "Release $TAG" |
| 24 | +
|
| 25 | + - name: Publish version DOI |
| 26 | + env: |
| 27 | + NEMAR_WEBHOOK_TOKEN: ${{ secrets.NEMAR_WEBHOOK_TOKEN }} |
| 28 | + run: | |
| 29 | + DATASET_ID="${{ github.event.repository.name }}" |
| 30 | + TAG="${{ github.ref_name }}" |
| 31 | + VERSION="${TAG#v}" |
| 32 | + RELEASE_URL="https://github.com/${{ github.repository }}/releases/tag/$TAG" |
| 33 | +
|
| 34 | + echo "Publishing DOI for $DATASET_ID version $VERSION" |
| 35 | +
|
| 36 | + if [ -z "$NEMAR_WEBHOOK_TOKEN" ]; then |
| 37 | + echo "NEMAR_WEBHOOK_TOKEN not configured, skipping DOI publish" |
| 38 | + exit 0 |
| 39 | + fi |
| 40 | +
|
| 41 | + RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \ |
| 42 | + "https://api.osc.earth/nemar/webhooks/publish-version-doi" \ |
| 43 | + -H "Content-Type: application/json" \ |
| 44 | + -H "X-Webhook-Token: $NEMAR_WEBHOOK_TOKEN" \ |
| 45 | + -d "{ |
| 46 | + \"dataset_id\": \"$DATASET_ID\", |
| 47 | + \"version\": \"$VERSION\", |
| 48 | + \"release_url\": \"$RELEASE_URL\" |
| 49 | + }") |
| 50 | +
|
| 51 | + HTTP_CODE=$(echo "$RESPONSE" | tail -1) |
| 52 | + BODY=$(echo "$RESPONSE" | head -n -1) |
| 53 | +
|
| 54 | + echo "Response: $BODY" |
| 55 | +
|
| 56 | + if [ "$HTTP_CODE" -ge 400 ]; then |
| 57 | + if echo "$BODY" | jq -e '.skipped == true' > /dev/null 2>&1; then |
| 58 | + echo "Skipped: No concept DOI exists for this dataset" |
| 59 | + exit 0 |
| 60 | + fi |
| 61 | + echo "::error::Failed to publish DOI (HTTP $HTTP_CODE)" |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | +
|
| 65 | + DOI=$(echo "$BODY" | jq -r '.version_doi // empty') |
| 66 | + if [ -n "$DOI" ]; then |
| 67 | + echo "Version DOI published: $DOI" |
| 68 | + fi |
| 69 | +
|
| 70 | + trigger-archive: |
| 71 | + name: Trigger Archive Generation |
| 72 | + needs: publish-doi |
| 73 | + runs-on: ubuntu-latest |
| 74 | + steps: |
| 75 | + - name: Dispatch archive generation |
| 76 | + env: |
| 77 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + run: | |
| 79 | + DATASET_ID="${{ github.event.repository.name }}" |
| 80 | + TAG="${{ github.ref_name }}" |
| 81 | + VERSION="${TAG#v}" |
| 82 | +
|
| 83 | + echo "Triggering archive generation for $DATASET_ID v$VERSION" |
| 84 | +
|
| 85 | + gh api "repos/${{ github.repository }}/dispatches" \ |
| 86 | + -f event_type=generate-archive \ |
| 87 | + -f "client_payload[dataset_id]=$DATASET_ID" \ |
| 88 | + -f "client_payload[version]=$VERSION" |
0 commit comments