Elffuss BraidHub

kikocis/continue public

main · 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 env:
28 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29 run: |
30 # Get PR number for the current commit using GitHub API
31 COMMIT_SHA=$(git rev-parse HEAD)
32 echo "Getting PR for commit: $COMMIT_SHA"
33
34 PR_NUMBER=$(curl -s -H "Authorization: token $GH_TOKEN" \
35 "https://api.github.com/repos/${{ github.repository }}/commits/$COMMIT_SHA/pulls" \
36 | jq -r '.[0].number // empty')
37
38 if [ -z "$PR_NUMBER" ]; then
39 echo "❌ Could not find PR for commit $COMMIT_SHA"
40 exit 1
41 fi
42
43 echo "Found PR number: $PR_NUMBER"
44 echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
45
46 - name: Find PR workflow run
47 id: find-run
48 env:
49 PR_NUMBER: ${{ steps.get-pr.outputs.pr_number }}
50 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51 run: |
52 echo "🔍 Getting branch name for PR #$PR_NUMBER..."
53
54 # Get the branch name for the PR
55 BRANCH_NAME=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" --json headRefName --jq '.headRefName')
56
57 if [ -z "$BRANCH_NAME" ]; then
58 echo "❌ Could not find PR #$PR_NUMBER"
59 exit 1
60 fi
61
62 echo "Branch name: $BRANCH_NAME"
63
64 # Get the latest successful workflow run for the branch
65 RUN_ID=$(gh run list \
66 --repo "${{ github.repository }}" \
67 --workflow="pr_checks.yaml" \
68 --branch="$BRANCH_NAME" \
69 --json databaseId,status,conclusion \
70 --jq ".[] | select(.status == \"completed\" and .conclusion == \"success\") | .databaseId" \
71 | head -1)
72
73 if [ -z "$RUN_ID" ]; then
74 echo "❌ No successful workflow run found for PR #$PR_NUMBER (branch: $BRANCH_NAME)"
75 exit 1
76 fi
77
78 echo "Found successful workflow run: $RUN_ID"
79 echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
80
81 - name: Download PR artifact
82 env:
83 RUN_ID: ${{ steps.find-run.outputs.run_id }}
84 PLATFORM: ${{ matrix.platform }}
85 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86 run: |
87 echo "📥 Downloading vscode-extension-build-$PLATFORM artifact from run $RUN_ID..."
88
89 # Create temporary directory for download
90 mkdir -p ./temp-download
91
92 # Download the artifact from the PR workflow run
93 if ! gh run download "$RUN_ID" \
94 --repo "${{ github.repository }}" \
95 --name "vscode-extension-build-$PLATFORM" \
96 --dir "./temp-download"; then
97 echo "❌ Failed to download artifact vscode-extension-build-$PLATFORM from run $RUN_ID"
98 exit 1
99 fi
100
101 echo "✅ Successfully downloaded artifact"
102
103 - name: Republish as main branch artifact
104 uses: actions/upload-artifact@v4
105 with:
106 name: vscode-extension-build-${{ matrix.platform }}
107 path: ./temp-download/*