Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 32 additions & 18 deletions .github/workflows/nightly_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,43 @@ jobs:
const owner = context.repo.owner;
const repo = context.repo.repo;

// Find default branch and its HEAD
// Get default branch info
const repoInfo = await github.rest.repos.get({ owner, repo });
const defaultBranch = repoInfo.data.default_branch;
const head = await github.rest.repos.getBranch({ owner, repo, branch: defaultBranch });

const head = await github.rest.repos.getBranch({
owner,
repo,
branch: defaultBranch
});

const headSha = head.data.commit.sha;
const shortSha = headSha.slice(0,7);
const shortSha = headSha.slice(0, 7);

// Try get the existing nightly release (single static tag)
let nightlyRelease = null;
try {
nightlyRelease = await github.rest.repos.getReleaseByTag({
owner, repo, tag: 'nightly'
});
} catch (e) {
if (e.status !== 404) throw e;
// List releases and find the most recent "<sha>_nightly"
const releases = await github.rest.repos.listReleases({
owner,
repo,
per_page: 50
});

let latestNightlySha = null;

for (const rel of releases.data) {
const name = rel.name || "";

const match = name.match(/^([0-9a-f]{7})_nightly$/i);
if (match) {
latestNightlySha = match[1];
break; // releases are returned newest-first
}
}

// Decide if we need to rebuild: compare short SHA in the release name
// Name format we set: "<shortsha>_nightly"
let shouldBuild = true;
if (nightlyRelease) {
const name = nightlyRelease.data.name || '';
const m = name.match(/^([0-9a-f]{7})_nightly$/i);
if (m && m[1] === shortSha) {
shouldBuild = false; // no new commits since last nightly

if (latestNightlySha) {
if (latestNightlySha === shortSha) {
shouldBuild = false;
}
}

Expand All @@ -62,6 +74,8 @@ jobs:
compile_sketch:
name: build ${{ matrix.board.name }}
runs-on: ubuntu-latest
needs: decide
if: ${{ needs.decide.outputs.should_build == 'true' }}
strategy:
fail-fast: false
matrix:
Expand Down