-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: remove veda-config related steps #181
Changes from 11 commits
822be31
79cfb96
29e5868
db787de
9e943a9
954ddaf
951b41e
0846b3a
e26b970
8aeaefa
e1a59cc
d41d629
e40df51
9345bff
a80142f
f10e854
70ab8ae
6210ae3
eb835b3
8fabafa
66626d1
57f1005
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
# This GitHub Actions workflow automates the process of | ||
# publishing dataset collections to a staging environment | ||
# and creating a pull request (PR) in the veda-config repository | ||
# with the dataset configuration. | ||
# It is triggered by a pull request to the main branch | ||
# that modifies any files within the ingestion-data/dataset-config/ directory | ||
# The workflow includes steps to | ||
# - publish the datasets, | ||
# - create a PR in veda-config repository, | ||
# - constantly updates the status of the workflow in the PR comment | ||
|
||
name: Publish collection to staging and create dataset config PR | ||
name: Publish collection to staging | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
branches: ['main', 'feat/automated-staging-publish'] | ||
paths: | ||
# Run the workflow only if files inside this path are updated | ||
- ingestion-data/dataset-config/* | ||
# - ingestion-data/staging/dataset-config/* | ||
- ingestion-data/testing/dataset-config/* | ||
|
||
jobs: | ||
dataset-publication-and-configuration: | ||
permissions: | ||
pull-requests: write | ||
contents: read | ||
runs-on: ubuntu-latest | ||
environment: staging | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is hardcoded for now to use the |
||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
@@ -38,9 +36,9 @@ jobs: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
WORKFLOW_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
body='### Workflow Status | ||
**Starting workflow...** [View action run]($WORKFLOW_URL) | ||
' | ||
body="### Workflow Status | ||
**Starting workflow...** [View action run]($WORKFLOW_URL)" | ||
echo "Body content: $body" | ||
|
||
# Get the PR number | ||
PR_NUMBER=${{ github.event.pull_request.number }} | ||
|
@@ -76,12 +74,13 @@ jobs: | |
- name: Get auth token | ||
id: get-token | ||
run: | | ||
echo "Vars: $vars" | ||
response=$(curl -X POST \ | ||
${{ vars.STAGING_COGNITO_DOMAIN }}/oauth2/token \ | ||
-H "Content-Type: application/x-www-form-urlencoded" \ | ||
-d "grant_type=client_credentials" \ | ||
-d "client_id=${{ vars.STAGING_CLIENT_ID }}" \ | ||
-d "client_secret=${{ secrets.STAGING_CLIENT_SECRET }}" | ||
-d "client_secret=${{ vars.STAGING_CLIENT_SECRET }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be stored in the environment secret? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using a secret in this case would be appropriate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
) | ||
|
||
access_token=$(echo "$response" | jq -r '.access_token') | ||
|
@@ -133,6 +132,7 @@ jobs: | |
) | ||
|
||
status_code=$(tail -n1 <<< "$response") | ||
echo "Status code is: $status_code" | ||
|
||
# Update status message based on response code | ||
if [ "$status_code" -eq 200 ] || [ "$status_code" -eq 201 ]; then | ||
|
@@ -168,19 +168,6 @@ jobs: | |
$status_message" | ||
gh api -X PATCH -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID -f body="$UPDATED_BODY" | ||
|
||
# Update PR comment | ||
- name: Update PR comment for PR creation | ||
if: success() | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COMMENT_ID: ${{ steps.init-comment.outputs.COMMENT_ID }} | ||
run: | | ||
CURRENT_BODY=$(gh api -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID --jq '.body') | ||
UPDATED_BODY="$CURRENT_BODY | ||
|
||
**Creating a PR in veda-config...**" | ||
gh api -X PATCH -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID -f body="$UPDATED_BODY" | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
|
@@ -198,78 +185,9 @@ jobs: | |
python3 scripts/mdx.py "$file" | ||
done | ||
|
||
- name: Set up Git | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
|
||
- name: Clone `veda-config` | ||
env: | ||
VEDA_CONFIG_GH_TOKEN: ${{ secrets.VEDA_CONFIG_GH_TOKEN }} | ||
run: git clone https://${{ env.VEDA_CONFIG_GH_TOKEN }}@github.com/${{ vars.VEDA_CONFIG_REPO_ORG }}/${{ vars.VEDA_CONFIG_REPO_NAME }}.git | ||
|
||
# Creates a PR in veda-config with the following changes: | ||
# 1. the mdx files for all published collections | ||
# 2. updates the stac/raster urls in .env file | ||
# This step needs a GH_TOKEN that has permissions to create a PR in veda-config | ||
- name: Create PR with changes | ||
id: create-pr | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
VEDA_CONFIG_GH_TOKEN: ${{ secrets.VEDA_CONFIG_GH_TOKEN }} | ||
COMMENT_ID: ${{ steps.publish-collections.outputs.COMMENT_ID }} | ||
PUBLISHED_COLLECTION_FILES: ${{ steps.publish-collections.outputs.success_collections }} | ||
run: | | ||
files_string=$(IFS=$'\n'; echo "${PUBLISHED_COLLECTION_FILES[*]}") | ||
hash=$(echo -n "$files_string" | md5sum | cut -d ' ' -f 1) | ||
NEW_BRANCH="add-dataset-$hash" | ||
cd ${{ vars.VEDA_CONFIG_REPO_NAME }} | ||
git fetch origin | ||
if git ls-remote --exit-code --heads origin $NEW_BRANCH; then | ||
git push origin --delete $NEW_BRANCH | ||
fi | ||
git checkout -b $NEW_BRANCH | ||
|
||
# Update the env vars to staging based on env vars | ||
sed -i "s|${{ vars.ENV_FROM }}|${{ vars.ENV_TO }}|g" .env | ||
cp -r ../datasets/* datasets/ | ||
git add . | ||
git commit -m "Add dataset(s)" | ||
git push origin $NEW_BRANCH | ||
PR_URL=$(GITHUB_TOKEN=$VEDA_CONFIG_GH_TOKEN gh pr create -H $NEW_BRANCH -B develop --title 'Add dataset [Automated workflow]' --body-file <(echo "Add datasets (Automatically created by Github action)")) | ||
|
||
echo "PR_URL=$PR_URL" >> $GITHUB_OUTPUT | ||
echo "PR creation succeeded" | ||
|
||
# Updates the comment with a link to the above PR | ||
- name: Update PR comment with PR creation result | ||
if: success() | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COMMENT_ID: ${{ steps.init-comment.outputs.COMMENT_ID }} | ||
run: | | ||
PR_URL=${{ steps.create-pr.outputs.PR_URL }} | ||
CURRENT_BODY=$(gh api -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID --jq '.body') | ||
UPDATED_BODY="$CURRENT_BODY | ||
|
||
**A PR has been created with the dataset configuration: 🗺️ [PR link]($PR_URL)**" | ||
gh api -X PATCH -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID -f body="$UPDATED_BODY" | ||
|
||
- name: Update PR comment on PR creation failure | ||
if: failure() && steps.create-pr.outcome == 'failure' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COMMENT_ID: ${{ steps.init-comment.outputs.COMMENT_ID }} | ||
run: | | ||
CURRENT_BODY=$(gh api -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID --jq '.body') | ||
UPDATED_BODY="$CURRENT_BODY | ||
|
||
**Failed ❌ to create a PR with the dataset configuration. 😔 **" | ||
gh api -X PATCH -H "Authorization: token $GITHUB_TOKEN" /repos/${{ github.repository }}/issues/comments/$COMMENT_ID -f body="$UPDATED_BODY" | ||
|
||
# If the workflow fails at any point, the PR comment will be updated | ||
- name: Update PR comment on overall workflow failure | ||
if: failure() && steps.create-pr.outcome != 'failure' | ||
if: failure() | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
COMMENT_ID: ${{ steps.init-comment.outputs.COMMENT_ID }} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"collection": "hls-swir-falsecolor-composite-TEST", | ||
"title": "HLS SWIR FalseColor Composite", | ||
"spatial_extent": { | ||
"xmin": -156.75, | ||
"ymin": 20.80, | ||
"xmax": -156.55, | ||
"ymax": 20.94 | ||
}, | ||
"temporal_extent": { | ||
"startdate": "2023-08-08T00:00:00Z", | ||
"enddate": "2023-08-08T23:59:59Z" | ||
}, | ||
"data_type": "cog", | ||
"license": "CC0-1.0", | ||
"description": "HLS falsecolor composite imagery using Bands 12, 8A, and 4.", | ||
"is_periodic": false, | ||
"time_density": "day", | ||
"sample_files": [ | ||
"s3://veda-data-store-staging/maui-fire/Lahaina_HLS_2023-08-08_SWIR_falsecolor_cog.tif", | ||
"s3://veda-data-store-staging/maui-fire/Lahaina_HLS_2023-08-13_SWIR_falsecolor_cog.tif" | ||
], | ||
"discovery_items": [ | ||
{ | ||
"discovery": "s3", | ||
"prefix": "maui-fire/", | ||
"bucket": "veda-data-store-staging", | ||
"filename_regex": "(.*)SWIR_falsecolor(.*).tif$" | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove this later but I added it to prove that it can be triggered on pushes to a branch