-
Notifications
You must be signed in to change notification settings - Fork 7
fix: improve X post release detection logic #141
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
Changes from all commits
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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,16 +11,76 @@ jobs: | |||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||
| - name: Get latest release | ||||||||||||||||||||||||||
| - name: Get latest release with changes | ||||||||||||||||||||||||||
| id: release | ||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||
| RELEASE=$(gh api /repos/${{ github.repository }}/releases/latest) | ||||||||||||||||||||||||||
| echo "tag=$(echo $RELEASE | jq -r .tag_name)" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||
| echo "url=$(echo $RELEASE | jq -r .html_url)" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||
| # Get the latest @evolution-sdk release with actual changes (not just dependency updates) | ||||||||||||||||||||||||||
| RELEASES=$(gh api /repos/${{ github.repository }}/releases --jq '[.[] | select(.tag_name | startswith("@evolution-sdk/"))]') | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Variables to track packages | ||||||||||||||||||||||||||
| FALLBACK_TAG="" | ||||||||||||||||||||||||||
| FALLBACK_URL="" | ||||||||||||||||||||||||||
| EVOLUTION_TAG="" | ||||||||||||||||||||||||||
| EVOLUTION_URL="" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| for i in $(seq 0 10); do | ||||||||||||||||||||||||||
| RELEASE=$(echo $RELEASES | jq ".[$i]") | ||||||||||||||||||||||||||
| if [ "$RELEASE" = "null" ]; then | ||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| CREATED=$(echo $RELEASE | jq -r .created_at) | ||||||||||||||||||||||||||
| CREATED_TIMESTAMP=$(date -d "$CREATED" +%s) | ||||||||||||||||||||||||||
| NOW=$(date +%s) | ||||||||||||||||||||||||||
| AGE=$((NOW - CREATED_TIMESTAMP)) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # If created in last hour, check if it has real changes (not just dependency updates) | ||||||||||||||||||||||||||
| if [ $AGE -lt 3600 ]; then | ||||||||||||||||||||||||||
| BODY=$(echo $RELEASE | jq -r .body) | ||||||||||||||||||||||||||
| TAG=$(echo $RELEASE | jq -r .tag_name) | ||||||||||||||||||||||||||
| URL=$(echo $RELEASE | jq -r .html_url) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Check for actual changes (not just "Updated dependencies") | ||||||||||||||||||||||||||
| CHANGES_SECTION=$(echo "$BODY" | grep -A 100 "Patch Changes\|Minor Changes\|Major Changes" | tail -n +2) | ||||||||||||||||||||||||||
| REAL_CHANGES=$(echo "$CHANGES_SECTION" | grep -v "Updated dependencies" | grep -v "^[[:space:]]*-[[:space:]]*@" | grep -v "^[[:space:]]*$" | head -1) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if [ -n "$REAL_CHANGES" ]; then | ||||||||||||||||||||||||||
| # Check if this is the main evolution package | ||||||||||||||||||||||||||
| if [[ "$TAG" == "@evolution-sdk/evolution@"* ]]; then | ||||||||||||||||||||||||||
| if [ -z "$EVOLUTION_TAG" ]; then | ||||||||||||||||||||||||||
| EVOLUTION_TAG=$TAG | ||||||||||||||||||||||||||
| EVOLUTION_URL=$URL | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||
| # Save as fallback if we haven't found one yet | ||||||||||||||||||||||||||
| if [ -z "$FALLBACK_TAG" ]; then | ||||||||||||||||||||||||||
| FALLBACK_TAG=$TAG | ||||||||||||||||||||||||||
| FALLBACK_URL=$URL | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Prioritize evolution package, fall back to other packages | ||||||||||||||||||||||||||
| if [ -n "$EVOLUTION_TAG" ]; then | ||||||||||||||||||||||||||
| CLEAN_TAG=$(echo $EVOLUTION_TAG | sed 's/@//g') | ||||||||||||||||||||||||||
| echo "tag=$CLEAN_TAG" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||
| echo "url=$EVOLUTION_URL" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||
| echo "found=true" >> $GITHUB_OUTPUT | ||||||||||||||||||||||||||
| elif [ -n "$FALLBACK_TAG" ]; then | ||||||||||||||||||||||||||
| CLEAN_TAG=$(echo $FALLBACK_TAG | sed 's/@//g') | ||||||||||||||||||||||||||
|
Comment on lines
+67
to
+72
|
||||||||||||||||||||||||||
| CLEAN_TAG=$(echo $EVOLUTION_TAG | sed 's/@//g') | |
| echo "tag=$CLEAN_TAG" >> $GITHUB_OUTPUT | |
| echo "url=$EVOLUTION_URL" >> $GITHUB_OUTPUT | |
| echo "found=true" >> $GITHUB_OUTPUT | |
| elif [ -n "$FALLBACK_TAG" ]; then | |
| CLEAN_TAG=$(echo $FALLBACK_TAG | sed 's/@//g') | |
| CLEAN_TAG=$(echo $EVOLUTION_TAG | sed 's/^@//') | |
| echo "tag=$CLEAN_TAG" >> $GITHUB_OUTPUT | |
| echo "url=$EVOLUTION_URL" >> $GITHUB_OUTPUT | |
| echo "found=true" >> $GITHUB_OUTPUT | |
| elif [ -n "$FALLBACK_TAG" ]; then | |
| CLEAN_TAG=$(echo $FALLBACK_TAG | sed 's/^@//') |
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.
echo $RELEASES | jq ...expands$RELEASESunquoted, which performs word splitting and re-flattens whitespace in the JSON before it reachesjq; while it may work in practice, it is fragile and can break with larger or more complex JSON payloads. To make this more robust, pass the JSON tojqwithout word splitting (for example by quoting$RELEASESor usingprintf), so the data structure is preserved exactly as returned bygh api.