2929 runs-on : ubuntu-latest
3030 environment : staging
3131 outputs :
32- publishedCollections : ${{ steps.publish-collections.outputs.success_collections }}
33- commentId : ${{ steps.init-comment.outputs.COMMENT_ID }}
32+ published_collections : ${{ steps.publish-collections.outputs.success_collections }}
33+ comment_id : ${{ steps.init-comment.outputs.COMMENT_ID }}
34+ has_new_files_to_promote : ${{ steps.changed-files.outputs.added_files_count != 0 }}
3435 steps :
3536 - uses : actions/checkout@v4
3637
7273 id : changed-files
7374 uses : tj-actions/changed-files@v45
7475 with :
75- files : |
76- **.json
76+ files : ingestion-data/staging/dataset-config/**.json
7777
7878 - name : List all newly added files
7979 env :
@@ -85,55 +85,35 @@ jobs:
8585 done
8686 echo "added_files_count: ${ADDED_FILES_COUNT}"
8787
88- # Uses service client creds to get token
89- # No username/password needed
90- - name : Get auth token
91- id : get-token
88+ - name : Exit early if no new files
89+ if : ${{ steps.changed-files.outputs.added_files_count == 0 }}
9290 run : |
93- echo "Vars: $vars"
94- response=$(curl -X POST \
95- ${{ vars.STAGING_COGNITO_DOMAIN }}/oauth2/token \
96- -H "Content-Type: application/x-www-form-urlencoded" \
97- -d "grant_type=client_credentials" \
98- -d "client_id=${{ vars.STAGING_CLIENT_ID }}" \
99- -d "client_secret=${{ secrets.STAGING_CLIENT_SECRET }}"
100- )
101-
102- access_token=$(echo "$response" | jq -r '.access_token')
103- echo "ACCESS_TOKEN=$access_token" >> $GITHUB_OUTPUT
91+ echo "🕵️ No new files found. Exiting workflow early."
92+ exit 0
10493
10594 # Makes request to /dataset/publish endpoint
10695 # Outputs only files that were successfully published
10796 # Used by other steps
10897 # If none of the requests are successful, workflow fails
10998 # Updates the PR comment with status of collection publication
11099 - name : Publish all newly added collections to staging
100+ if : ${{ steps.changed-files.outputs.added_files_count != 0 }}
111101 id : publish-collections
112102 env :
113103 ADDED_FILES : ${{ steps.changed-files.outputs.added_files }}
114- WORKFLOWS_URL : ${{ vars.STAGING_WORKFLOWS_URL }}
115104 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
116- AUTH_TOKEN : ${{ steps.get-token.outputs.ACCESS_TOKEN }}
117105 COMMENT_ID : ${{ steps.init-comment.outputs.COMMENT_ID }}
106+ STAGING_SM2A_ADMIN_USERNAME : ${{ secrets.STAGING_SM2A_ADMIN_USERNAME }}
107+ STAGING_SM2A_ADMIN_PASSWORD : ${{ secrets.STAGING_SM2A_ADMIN_PASSWORD }}
108+ STAGING_SM2A_API_URL : ${{ vars.STAGING_SM2A_API_URL }}
109+ DATASET_DAG_NAME : ${{ vars.DATASET_DAG_NAME }}
118110 run : |
119- if [ -z "$WORKFLOWS_URL" ]; then
120- echo "WORKFLOWS_URL is not set"
121- exit 1
122- fi
123-
124- if [ -z "$AUTH_TOKEN" ]; then
125- echo "AUTH_TOKEN is not set"
126- exit 1
127- fi
128-
129- publish_url="${WORKFLOWS_URL%/}/dataset/publish"
130- bearer_token=$AUTH_TOKEN
111+ pip install -r ./scripts/requirements.txt
131112
132113 # Track successful publications
133114 all_failed=true
134115 declare -a success_collections=()
135- status_message='### Collection Publication Status
136- '
116+ status_message="### Collection Publication Status"
137117
138118 for file in ${ADDED_FILES}; do
139119 echo $file
@@ -142,25 +122,21 @@ jobs:
142122 collection_id=$(jq -r '.collection' "$file")
143123
144124 echo "Publishing $collection_id"
145- response=$(curl -s -w "%{http_code}" -o response.txt -X POST "$publish_url" \
146- -H "Content-Type: application/json" \
147- -H "Authorization: Bearer $AUTH_TOKEN" \
148- -d "$dataset_config"
149- )
150125
151- status_code=$(tail -n1 <<< "$response")
126+ response=$(python3 ./scripts/promote_collection.py "$file" "staging")
127+ echo "Processed file: $file"
128+ status_code=$(echo "$response" | jq -r '.statusCode' | head -n1)
129+ echo "Status Code: $status_code"
152130
153131 # Update status message based on response code
154- if [ " $status_code" -eq 200 ] || [ " $status_code" -eq 201 ]; then
132+ if [[ $status_code -eq 200 ]] || [[ $status_code -eq 201 ] ]; then
155133 echo "$collection_id successfully published ✅"
156- status_message+="- **$collection_id**: Successfully published ✅
157- "
134+ status_message+="- **$collection_id**: Successfully published ✅"
158135 success_collections+=("$file")
159136 all_failed=false
160137 else
161138 echo "$collection_id failed to publish ❌"
162- status_message+="- **$collection_id**: Failed to publish. Error code $status_code. ❌
163- "
139+ status_message+="- **$collection_id**: Failed to publish. Error code $status_code. ❌"
164140 fi
165141 else
166142 echo "File $file does not exist"
@@ -207,7 +183,23 @@ jobs:
207183 ** ❌ The workflow run failed. [See logs here]($WORKFLOW_URL)**"
208184 gh api -X PATCH -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID -f body="$UPDATED_BODY"
209185
186+ # If the workflow fails at any point, the PR comment will be updated
187+
188+ - name : Update PR comment if no new files
189+ if : ${{ steps.changed-files.outputs.added_files_count == 0 }}
190+ env :
191+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
192+ COMMENT_ID : ${{ steps.init-comment.outputs.COMMENT_ID }}
193+ run : |
194+ WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
195+ CURRENT_BODY=$(gh api -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID --jq '.body')
196+ UPDATED_BODY="$CURRENT_BODY
197+
198+ 🕵️ No new files found. No files will be published to staging or promoted to production."
199+ gh api -X PATCH -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID -f body="$UPDATED_BODY"
200+
210201 create-mdx-files-and-open-pr :
202+ if : ${{ needs.publish-new-datasets.outputs.has_new_files_to_promote == 'true' }}
211203 runs-on : ubuntu-latest
212204 environment : staging
213205 needs : publish-new-datasets
@@ -217,12 +209,12 @@ jobs:
217209
218210 - name : Use output from publish-new-datasets
219211 run : |
220- echo "The output from the previous step is: ${{ needs.publish-new-datasets.outputs.publishedCollections }}"
212+ echo "The output from the previous step is: ${{ needs.publish-new-datasets.outputs.published_collections }}"
221213
222214 # Creates a slim dataset mdx file for each collection based on the dataset config json
223215 - name : Create dataset mdx for given collections
224216 env :
225- PUBLISHED_COLLECTION_FILES : ${{ needs.publish-new-datasets.outputs.publishedCollections }}
217+ PUBLISHED_COLLECTION_FILES : ${{ needs.publish-new-datasets.outputs.published_collections }}
226218 run : |
227219 echo $PUBLISHED_COLLECTION_FILES
228220 collection_ids=""
@@ -238,14 +230,27 @@ jobs:
238230 echo "Final collection_ids: $collection_ids"
239231 echo "collection_ids=${collection_ids}" >> $GITHUB_ENV
240232
233+ - name : Prepare temp directory for artifacts
234+ run : |
235+ mkdir -p /tmp/upload-artifacts
236+ for file in $(echo "${{ needs.publish-new-datasets.outputs.published_collections }}" | tr ',' ' '); do
237+ if [ -f "$file" ]; then
238+ cp "$file" /tmp/upload-artifacts/
239+ else
240+ echo "Warning: File not found - $file"
241+ fi
242+ done
243+
244+ - name : List files in temp directory
245+ run : ls -lah /tmp/upload-artifacts
246+
241247 - name : Upload published collections files as directory artifact
242248 uses : actions/upload-artifact@v4
243249 env :
244- PUBLISHED_COLLECTION_FILES : ${{ needs.publish-new-datasets.outputs.publishedCollections }}
245250 ARTIFACT_RETENTION_DAYS : ${{ vars.ARTIFACT_RETENTION_DAYS }}
246251 with :
247252 name : collections-to-promote-from-${{ github.event.pull_request.number }}
248- path : ${{ env.PUBLISHED_COLLECTION_FILES }}
253+ path : /tmp/upload-artifacts/*
249254 retention-days : ${{ env.ARTIFACT_RETENTION_DAYS }}
250255
251256 - name : Save Workflow Run ID
@@ -357,7 +362,7 @@ jobs:
357362 - name : Create veda-config PR with changes
358363 id : create-pr
359364 env :
360- COMMENT_ID : ${{ needs.publish-new-datasets.outputs.commentId }}
365+ COMMENT_ID : ${{ needs.publish-new-datasets.outputs.comment_id }}
361366 PUBLISHED_COLLECTION_FILES : ${{ steps.publish-collections.outputs.success_collections }}
362367 run : |
363368 cd veda-config
@@ -401,7 +406,7 @@ jobs:
401406 if : success()
402407 env :
403408 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
404- COMMENT_ID : ${{ needs.publish-new-datasets.outputs.commentId }}
409+ COMMENT_ID : ${{ needs.publish-new-datasets.outputs.comment_id }}
405410 run : |
406411 PR_URL=${{ steps.create-pr.outputs.PR_URL }}
407412 CURRENT_BODY=$(gh api -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID --jq '.body')
@@ -414,7 +419,7 @@ jobs:
414419 if : failure() && steps.create-pr.outcome == 'failure'
415420 env :
416421 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
417- COMMENT_ID : ${{ needs.publish-new-datasets.outputs.commentId }}
422+ COMMENT_ID : ${{ needs.publish-new-datasets.outputs.comment_id }}
418423 run : |
419424 CURRENT_BODY=$(gh api -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID --jq '.body')
420425 UPDATED_BODY="$CURRENT_BODY
@@ -427,7 +432,7 @@ jobs:
427432 if : failure() && steps.create-pr.outcome != 'failure'
428433 env :
429434 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
430- COMMENT_ID : ${{ needs.publish-new-datasets.outputs.commentId }}
435+ COMMENT_ID : ${{ needs.publish-new-datasets.outputs.comment_id }}
431436 run : |
432437 WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
433438 CURRENT_BODY=$(gh api -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID --jq '.body')
0 commit comments