From a36157e40f0951a1c4c4d85486c2f708abedf983 Mon Sep 17 00:00:00 2001 From: peelz Date: Sat, 27 May 2023 14:47:05 -0400 Subject: [PATCH] Add CI workflow for generating nightly builds --- .github/workflows/create-prerelease.yml | 86 +++++++++++++++++++++++++ .github/workflows/on-push-master.yml | 3 + .github/workflows/publish-release.yml | 22 +++++-- 3 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/create-prerelease.yml diff --git a/.github/workflows/create-prerelease.yml b/.github/workflows/create-prerelease.yml new file mode 100644 index 000000000..50ffcc2b7 --- /dev/null +++ b/.github/workflows/create-prerelease.yml @@ -0,0 +1,86 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json + +name: Create pre-release + +on: + schedule: + - cron: 0 0 * * * + workflow_dispatch: + +jobs: + check-if-release-needed: + runs-on: ubuntu-latest + outputs: + has-new-commits: "true" + steps: + - name: Extract branch name + id: extract-branch-name + run: | + echo "result=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_OUTPUT" + - name: Sanity checks + if: ${{ github.event_name == 'workflow_dispatch' && steps.extract-branch-name.outputs.result != 'develop' }} + run: | + echo "::error::this workflow can only be run on the \"develop\" branch" + exit 1 + + - name: Get latest nightly-tagged commit + id: get-latest-tag + uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 + with: + result-encoding: string + script: | + try { + const ref = await github.rest.git.getRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: "tags/nightly", + }); + return ref.data.object.sha; + } catch (err) { + if (err.name === "HttpError" && err.status === 404) { + return "tag-doesnt-exist"; + } + throw err; + } + + - name: Get latest commit on dev branch + id: get-latest-commit + uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 + with: + result-encoding: string + script: | + const ref = await github.rest.git.getRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: "heads/develop", + }); + return ref.data.object.sha; + + - name: Check for new commits + id: check-for-new-commits + if: ${{ steps.get-latest-tag.outputs.result != 'tag-doesnt-exist' }} + env: + LATEST_TAGGED_SHA: "${{ steps.get-latest-tag.outputs.result }}" + LATEST_SHA: "${{ steps.get-latest-commit.outputs.result }}" + run: | + if [[ -z "$LATEST_TAGGED_SHA" ]]; then + echo "::error::LATEST_TAGGED_SHA env var is invalid" + exit 1 + fi + if [[ -z "$LATEST_SHA" ]]; then + echo "::error::LATEST_TAGGED_SHA env var is invalid" + exit 1 + fi + + if [[ "$LATEST_TAGGED_SHA" == "$LATEST_SHA" ]]; then + echo "has-new-commits=false" >> "$GITHUB_STATE" + fi + + publish-release: + needs: [check-if-release-needed] + if: ${{ needs.check-if-release-needed.outputs.has-new-commits == 'true' }} + uses: ./.github/workflows/publish-release.yml + with: + ref: ${{ github.event.ref }} + tag: nightly + prerelease: true diff --git a/.github/workflows/on-push-master.yml b/.github/workflows/on-push-master.yml index 5aa5d4f97..debce86f5 100644 --- a/.github/workflows/on-push-master.yml +++ b/.github/workflows/on-push-master.yml @@ -19,3 +19,6 @@ jobs: publish-release: uses: ./.github/workflows/publish-release.yml + with: + ref: ${{ github.event.ref }} + tag: latest diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 88c3e5617..77fce65ca 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -3,8 +3,21 @@ name: Publish release on: - workflow_dispatch: workflow_call: + inputs: + ref: + description: "The git ref to checkout, build from and release" + required: true + type: string + tag: + description: "The tag of the release" + required: true + type: string + prerelease: + description: "Prerelease" + required: false + default: false + type: boolean env: CI_DIR: 2049ef39-42a2-46d2-b513-ee6d2e3a7b15 @@ -56,7 +69,7 @@ jobs: build: uses: ./.github/workflows/build.yml with: - ref: ${{ github.event.ref }} + ref: ${{ inputs.ref }} publish-release: runs-on: ubuntu-latest @@ -146,8 +159,9 @@ jobs: - name: Publish release uses: notpeelz/action-gh-create-release@a12edfc71daf5daa7922b931c28e2bf88d3b2ced # v5.0.0 with: - token: ${{ github.token }} - tag: latest + target: ${{ inputs.ref }} + tag: ${{ inputs.tag }} + prerelease: ${{ inputs.prerelease }} strategy: replace title: "Automatic build" body: "Automatic build"