@@ -3,19 +3,13 @@ name: Continuous Integration
33on :
44 pull_request :
55 branches : ["**"]
6- types : [opened, synchronize, reopened, closed]
76 push :
87 branches : ["main"]
98
10- env :
11- BRANCH_NAME : pr-${{ github.event.pull_request.number }}
12- CLOUDFLARE_PAGES_PROJECT_NAME : typelevel-website
13-
149jobs :
1510 build :
1611 name : Build and Test
1712 runs-on : ubuntu-latest
18- if : github.event.action != 'closed'
1913 steps :
2014 - uses : actions/checkout@v6
2115 - uses : actions/setup-java@v5
@@ -28,55 +22,29 @@ jobs:
2822 scala-cli-version : 1.12.2
2923 - run : scala-cli fmt --check .
3024 - run : scala-cli --server=false build.scala
31- - name : Publish to Cloudflare Pages
32- if : github.event_name == 'pull_request' && github.event.pull_request.merged != true
33- uses : cloudflare/wrangler-action@v4
25+ - name : Save PR number
26+ if : github.event_name == 'pull_request'
27+ run : echo "${{ github.event.pull_request.number }}" > pr_number.txt
28+ - name : Upload site artifact
29+ if : github.event_name == 'pull_request'
30+ uses : actions/upload-artifact@v4
31+ with :
32+ name : site
33+ path : target
34+ if-no-files-found : error
35+ retention-days : 30
36+ - name : Upload PR number artifact
37+ if : github.event_name == 'pull_request'
38+ uses : actions/upload-artifact@v4
3439 with :
35- apiToken : ${{ secrets.CLOUDFLARE_API_TOKEN }}
36- accountId : ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
37- gitHubToken : ${{ secrets.GITHUB_TOKEN }}
38- command : pages deploy ./target --project-name=${{ env.CLOUDFLARE_PAGES_PROJECT_NAME }} --branch=${{ env.BRANCH_NAME }}
39- - if : github.event_name != 'pull_request'
40+ name : pr-number
41+ path : pr_number.txt
42+ if-no-files-found : error
43+ retention-days : 30
44+ - name : Publish to GitHub Pages
45+ if : github.event_name == 'push'
4046 uses : peaceiris/actions-gh-pages@v4.0.0
4147 with :
4248 github_token : ${{ secrets.GITHUB_TOKEN }}
4349 publish_dir : target
4450 cname : typelevel.org
45-
46- cleanup-preview :
47- name : Delete Cloudflare Pages preview deployments
48- runs-on : ubuntu-latest
49- if : github.event_name == 'pull_request' && github.event.action == 'closed'
50- steps :
51- - name : Delete deployments for this PR's branch
52- env :
53- CLOUDFLARE_API_TOKEN : ${{ secrets.CLOUDFLARE_API_TOKEN }}
54- CLOUDFLARE_ACCOUNT_ID : ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
55- run : |
56- set -euo pipefail
57-
58- API="https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/$CLOUDFLARE_PAGES_PROJECT_NAME/deployments"
59- AUTH_HEADER="Authorization: Bearer $CLOUDFLARE_API_TOKEN"
60-
61- page=1
62- ids=()
63- while :; do
64- response=$(curl -sf -H "$AUTH_HEADER" "$API?page=$page&per_page=25")
65- count=$(echo "$response" | jq '.result | length')
66- [ "$count" -eq 0 ] && break
67- while IFS= read -r id; do
68- ids+=("$id")
69- done < <(echo "$response" | jq -r --arg branch "$BRANCH_NAME" \
70- '.result[] | select(.deployment_trigger.metadata.branch == $branch) | .id')
71- page=$((page + 1))
72- done
73-
74- if [ ${#ids[@]} -eq 0 ]; then
75- echo "No preview deployments found for branch $BRANCH_NAME"
76- exit 0
77- fi
78-
79- for id in "${ids[@]}"; do
80- echo "Deleting deployment $id"
81- curl -sf -X DELETE -H "$AUTH_HEADER" "$API/$id?force=true"
82- done
0 commit comments