Elffuss BraidHub

kikocis/continue public

80ffc97db92a · 3.5 KiBRawPermalink
1name: Main Branch Build
2
3# Download and republish VS Code extension artifacts when code is merged to main
4on:
5 push:
6 branches:
7 - main
8 workflow_dispatch:
9 inputs:
10 test_pr_number:
11 description: "PR number to test with"
12 required: true
13
14jobs:
15 republish-pr-artifacts:
16 runs-on: ubuntu-latest
17 strategy:
18 matrix:
19 platform: [Linux, macOS]
20 steps:
21 - uses: actions/checkout@v5
22 with:
23 fetch-depth: 2 # Get the last 2 commits to find the merge commit
24
25 - name: Get merged PR number
26 id: get-pr
27 run: |
28 # Get the commit message of the merge commit
29 COMMIT_MSG=$(git log --format=%B -n 1 HEAD)
30 echo "Commit message: $COMMIT_MSG"
31
32 # Extract PR number from merge commit message (format: "Merge pull request #123 from...")
33 PR_NUMBER=$(echo "$COMMIT_MSG" | grep -o "Merge pull request #[0-9]*" | grep -o "[0-9]*" || echo "6723")
34
35 if [ -z "$PR_NUMBER" ]; then
36 echo "❌ Could not extract PR number from commit message. This might not be a PR merge."
37 echo "Commit message was: $COMMIT_MSG"
38 exit 1
39 fi
40
41 echo "Found PR number: $PR_NUMBER"
42 echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
43
44 - name: Find PR workflow run
45 id: find-run
46 env:
47 PR_NUMBER: ${{ steps.get-pr.outputs.pr_number }}
48 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49 run: |
50 echo "🔍 Getting branch name for PR #$PR_NUMBER..."
51
52 # Get the branch name for the PR
53 BRANCH_NAME=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json headRefName --jq '.headRefName')
54
55 if [ -z "$BRANCH_NAME" ]; then
56 echo "❌ Could not find PR #$PR_NUMBER"
57 exit 1
58 fi
59
60 echo "Branch name: $BRANCH_NAME"
61
62 # Get the latest successful workflow run for the branch
63 RUN_ID=$(gh run list \
64 --repo "${{ github.repository }}" \
65 --workflow="pr_checks.yaml" \
66 --branch="$BRANCH_NAME" \
67 --json databaseId,status,conclusion \
68 --jq ".[] | select(.status == \"completed\" and .conclusion == \"success\") | .databaseId" \
69 | head -1)
70
71 if [ -z "$RUN_ID" ]; then
72 echo "❌ No successful workflow run found for PR #$PR_NUMBER (branch: $BRANCH_NAME)"
73 exit 1
74 fi
75
76 echo "Found successful workflow run: $RUN_ID"
77 echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
78
79 - name: Download PR artifact
80 env:
81 RUN_ID: ${{ steps.find-run.outputs.run_id }}
82 PLATFORM: ${{ matrix.platform }}
83 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84 run: |
85 echo "📥 Downloading vscode-extension-build-$PLATFORM artifact from run $RUN_ID..."
86
87 # Create temporary directory for download
88 mkdir -p ./temp-download
89
90 # Download the artifact from the PR workflow run
91 if ! gh run download "$RUN_ID" \
92 --repo "${{ github.repository }}" \
93 --name "vscode-extension-build-$PLATFORM" \
94 --dir "./temp-download"; then
95 echo "❌ Failed to download artifact vscode-extension-build-$PLATFORM from run $RUN_ID"
96 exit 1
97 fi
98
99 echo "✅ Successfully downloaded artifact"
100
101 - name: Republish as main branch artifact
102 uses: actions/upload-artifact@v4
103 with:
104 name: vscode-extension-build-${{ matrix.platform }}
105 path: ./temp-download/*