|
| 1 | +name: Update Showcases Dependencies |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Trigger Legend Stack Release"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + force_version: |
| 11 | + description: "Force a specific version to manually downgrade or fix a broken release (optional)" |
| 12 | + required: false |
| 13 | + default: "" |
| 14 | + |
| 15 | +jobs: |
| 16 | + update-showcases: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + pull-requests: write |
| 22 | + steps: |
| 23 | + - name: Checkout Code |
| 24 | + |
| 25 | + with: |
| 26 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + |
| 28 | + - name: Fetch Latest Engine Version |
| 29 | + id: fetch-version |
| 30 | + run: | |
| 31 | + if [ "${{ github.event.inputs.force_version }}" != "" ]; then |
| 32 | + VERSION="${{ github.event.inputs.force_version }}" |
| 33 | + else |
| 34 | + echo "Fetching latest successful release from Legend Engine..." |
| 35 | + RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 36 | + "https://api.github.com/repos/finos/legend-engine/releases/latest") |
| 37 | + VERSION=$(echo "$RESPONSE" | jq -r '.tag_name // empty' | sed 's/^legend-engine-//') |
| 38 | + fi |
| 39 | +
|
| 40 | + if [ -z "$VERSION" ] || [ "$VERSION" == "null" ]; then |
| 41 | + echo "Error: Could not determine version." |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 45 | +
|
| 46 | + - name: Check Idempotency |
| 47 | + id: check |
| 48 | + run: | |
| 49 | + POM_PATH=$(find . -name "pom.xml" | grep "showcases/pom.xml" | head -n 1) |
| 50 | + if [ -z "$POM_PATH" ]; then exit 1; fi |
| 51 | +
|
| 52 | + CURRENT_VERSION=$(sed -n 's/.*<legend.engine.version>\(.*\)<\/legend.engine.version>.*/\1/p' "$POM_PATH" | head -n 1 | xargs) |
| 53 | + LATEST_VERSION="${{ steps.fetch-version.outputs.version }}" |
| 54 | +
|
| 55 | + if [ "$CURRENT_VERSION" == "$LATEST_VERSION" ]; then |
| 56 | + echo "should_update=false" >> $GITHUB_OUTPUT |
| 57 | + else |
| 58 | + echo "should_update=true" >> $GITHUB_OUTPUT |
| 59 | + fi |
| 60 | + echo "pom_path=$POM_PATH" >> $GITHUB_OUTPUT |
| 61 | +
|
| 62 | + - name: Wait for Maven Central Sync |
| 63 | + if: steps.check.outputs.should_update == 'true' |
| 64 | + run: | |
| 65 | + artifact_group='org.finos.legend.engine' |
| 66 | + artifact_name='legend-engine-extensions-collection-generation' |
| 67 | + artifact_version='${{ steps.fetch-version.outputs.version }}' |
| 68 | + max_retries=120 |
| 69 | + retries=0 |
| 70 | + while true; do |
| 71 | + response=$(curl -s -o /dev/null -w "%{http_code}" "https://central.sonatype.com/artifact/$artifact_group/$artifact_name/$artifact_version") |
| 72 | + if [ "$response" == "200" ]; then |
| 73 | + echo "Artifact is available in Maven Central." |
| 74 | + break |
| 75 | + else |
| 76 | + retries=$((retries + 1)) |
| 77 | + if [ "$retries" -gt "$max_retries" ]; then |
| 78 | + echo "Maximum number of retries reached. Artifact is not available in Maven Central." |
| 79 | + exit 1 |
| 80 | + fi |
| 81 | + echo "Artifact is not available in Maven Central. Retrying in 1 minute..." |
| 82 | + sleep 1m |
| 83 | + fi |
| 84 | + done |
| 85 | + sleep 1m # Sleep for 1 more minute to be on safer side |
| 86 | +
|
| 87 | + - name: Setup Java |
| 88 | + if: steps.check.outputs.should_update == 'true' |
| 89 | + uses: actions/setup-java@v3 |
| 90 | + with: |
| 91 | + java-version: "11" |
| 92 | + distribution: "temurin" |
| 93 | + cache: "maven" |
| 94 | + |
| 95 | + - name: Update Version Property |
| 96 | + if: steps.check.outputs.should_update == 'true' |
| 97 | + run: | |
| 98 | + mvn org.codehaus.mojo:versions-maven-plugin:2.7:set-property \ |
| 99 | + -Dproperty=legend.engine.version \ |
| 100 | + -DnewVersion=${{ steps.fetch-version.outputs.version }} \ |
| 101 | + -DgenerateBackupPoms=false \ |
| 102 | + -f ${{ steps.check.outputs.pom_path }} |
| 103 | +
|
| 104 | + if ! grep -q "${{ steps.fetch-version.outputs.version }}" "${{ steps.check.outputs.pom_path }}"; then |
| 105 | + echo "Error: POM version was not updated!" |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | +
|
| 109 | + - name: Verify Build Compatibility |
| 110 | + if: steps.check.outputs.should_update == 'true' |
| 111 | + run: mvn clean compile -f ${{ steps.check.outputs.pom_path }} |
| 112 | + |
| 113 | + - name: Create Pull Request |
| 114 | + id: create-pr |
| 115 | + if: steps.check.outputs.should_update == 'true' |
| 116 | + env: |
| 117 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + run: | |
| 119 | + VERSION="${{ steps.fetch-version.outputs.version }}" |
| 120 | + BRANCH="automated/showcases-update-${VERSION}" |
| 121 | + DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name) |
| 122 | +
|
| 123 | + git config --global user.name "github-actions[bot]" |
| 124 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 125 | +
|
| 126 | + git checkout -b "$BRANCH" || git checkout "$BRANCH" |
| 127 | + git add ${{ steps.check.outputs.pom_path }} |
| 128 | + git commit -m "chore: update showcases engine dependency to ${VERSION}" |
| 129 | + git push origin "$BRANCH" --force |
| 130 | +
|
| 131 | + # Create PR, or if it exists, get the URL of the existing one |
| 132 | + PR_URL=$(gh pr create \ |
| 133 | + --title "chore: update showcases engine dependency to ${VERSION}" \ |
| 134 | + --body "Automated dependency update to match Legend Engine release **${VERSION}**." \ |
| 135 | + --base "master" \ |
| 136 | + --head "$BRANCH" \ |
| 137 | + --label "dependencies,automated" --json url --jq .url 2>/dev/null || \ |
| 138 | + gh pr list --head "$BRANCH" --base "master" --json url --jq '.[0].url') |
| 139 | +
|
| 140 | + echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT |
| 141 | +
|
| 142 | + - name: Generate Summary |
| 143 | + if: always() |
| 144 | + run: | |
| 145 | + echo "### 🚀 Dependency Update Summary" >> $GITHUB_STEP_SUMMARY |
| 146 | + echo "* **Engine Version Found:** \`${{ steps.fetch-version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY |
| 147 | +
|
| 148 | + if [ "${{ steps.check.outputs.should_update }}" == "true" ]; then |
| 149 | + echo "* **Status:** 🆕 Update Required" >> $GITHUB_STEP_SUMMARY |
| 150 | + echo "* **Action:** A Pull Request has been generated to update the POM file." >> $GITHUB_STEP_SUMMARY |
| 151 | + echo "* **PR Link:** ${{ steps.create-pr.outputs.pr_url }}" >> $GITHUB_STEP_SUMMARY |
| 152 | + else |
| 153 | + echo "* **Status:** ✅ Up to Date" >> $GITHUB_STEP_SUMMARY |
| 154 | + echo "* **Action:** No changes needed. The Showcases are already using the latest version." >> $GITHUB_STEP_SUMMARY |
| 155 | + fi |
| 156 | +
|
| 157 | + echo "* **Workflow Result:** ${{ job.status == 'success' && '🟢 Success' || '🔴 Failed' }}" >> $GITHUB_STEP_SUMMARY |
0 commit comments