blob: 44494eb0683a941a2062f1a76fcc3082b00d98b6 [file] [log] [blame]
Josh Bleecher Snyder7b00c2c2025-07-02 12:24:30 -07001name: Release Build (Nightly)
2
3on:
4 schedule:
5 - cron: "47 9 * * *" # 1:47 AM Pacific Time (9:47 UTC)
6 workflow_dispatch: # Allow manual triggering
7
8permissions:
9 contents: write
10
11jobs:
12 nightly:
13 runs-on: ubuntu-latest
14 if: github.ref == 'refs/heads/main'
15 steps:
16 - name: Checkout
17 uses: actions/checkout@v4
18 with:
19 fetch-depth: 0
20
21 - name: Set up Node.js
22 uses: actions/setup-node@v4
23 with:
24 node-version: "20"
25 cache: "npm"
26 cache-dependency-path: "webui/package-lock.json"
27
28 - uses: actions/setup-go@v5
29 with:
30 go-version-file: "${{ inputs.working-directory || '.'}}/go.mod"
31 cache: true
32
33 - name: Check for changes since last tag
34 id: check_changes
35 run: |
36 git fetch --tags --force
37 # find latest nightly tag that looks like nightly/v0.0.N
38 latest_nightly=$(git tag -l "nightly/v0.0.*" --sort=-v:refname | head -n1)
39 if [ -z "$latest_nightly" ]; then
40 echo "has_changes=true" >> $GITHUB_OUTPUT
41 echo "tag=v0.0.1" >> $GITHUB_OUTPUT
42 echo "nightly_tag=nightly/v0.0.1" >> $GITHUB_OUTPUT
43 else
44 echo "Latest nightly tag is $latest_nightly"
45 # Check if there are any new commits since the last nightly tag
46 changes=$(git log $latest_nightly..HEAD --oneline)
47 if [ -z "$changes" ]; then
48 echo "No new changes since last nightly tag, skipping nightly build"
49 echo "has_changes=false" >> $GITHUB_OUTPUT
50 else
51 echo "Changes found since last nightly tag:"
52 echo "$changes"
53 echo "has_changes=true" >> $GITHUB_OUTPUT
54 # Extract N from nightly/v0.0.N and increment
55 version_part="${latest_nightly#nightly/v0.0.}"
56 new_n=$((version_part + 1))
57 new_tag="v0.0.${new_n}"
58 new_nightly_tag="nightly/v0.0.${new_n}"
59 echo "tag=$new_tag" >> $GITHUB_OUTPUT
60 echo "nightly_tag=$new_nightly_tag" >> $GITHUB_OUTPUT
61 fi
62 fi
63
64 - name: Create and push nightly git tag
65 if: steps.check_changes.outputs.has_changes == 'true'
66 env:
67 TAG: ${{ steps.check_changes.outputs.tag }}
68 NIGHTLY_TAG: ${{ steps.check_changes.outputs.nightly_tag }}
69 run: |
70 git config user.name "Sketch Nightly Bot"
71 git config user.email "hello@sketch.dev"
72 git tag -a "$TAG" -m "Nightly build $TAG"
73 git tag -a "$NIGHTLY_TAG" -m "Nightly build tracking tag for $TAG"
74 git push origin "$TAG"
75 git push origin "$NIGHTLY_TAG"
76
77 - name: Run GoReleaser (Nightly)
78 if: steps.check_changes.outputs.has_changes == 'true'
79 uses: goreleaser/goreleaser-action@v4
80 with:
81 version: latest
82 args: release --clean
83 env:
84 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85
86 - name: Mark release as prerelease
87 if: steps.check_changes.outputs.has_changes == 'true'
88 uses: actions/github-script@v6
89 with:
90 script: |
91 const tag = process.env.TAG;
92 const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
93 const release = await github.rest.repos.getReleaseByTag({ owner, repo, tag });
94 await github.rest.repos.updateRelease({
95 owner,
96 repo,
97 release_id: release.data.id,
98 prerelease: true
99 });
100 env:
101 TAG: ${{ steps.check_changes.outputs.tag }}