Skip to content

Commit

Permalink
Merge pull request #17 from YuriSizov/make-ci-reusable
Browse files Browse the repository at this point in the history
CI: Make routines reusable and enable PR tests
  • Loading branch information
YuriSizov authored Jun 3, 2024
2 parents 08c7492 + 7efbe26 commit 5a94078
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ runs:
with:
version: ${{ inputs.emscripten_version }}
actions-cache-folder: emsdk-cache
cache-key: emsdk-${{ env.SCONS_PLATFORM }}-main
cache-key: emsdk-${{ env.SCONS_PLATFORM }}-${{ env.GIT_BASE_REF }}-${{ inputs.emscripten_version }}

- name: "Web: Verify Emscripten"
if: ${{ env.SCONS_PLATFORM == 'web' }}
Expand Down
6 changes: 4 additions & 2 deletions .github/actions/publish-extension/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ inputs:
default: "bin"
platform:
default: ""
release-version:
required: true

runs:
using: "composite"
Expand All @@ -19,9 +21,9 @@ runs:
path: ${{ inputs.path }}
filename: libgdsion-${{ inputs.platform }}.zip

- name: Update the rolling release with the artifact
- name: Update the release with the platform artifact
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload latest-unstable ${{ inputs.directory }}/libgdsion-${{ inputs.platform }}.zip --clobber
gh release upload ${{ inputs.release-version }} ${{ inputs.directory }}/libgdsion-${{ inputs.platform }}.zip --clobber
19 changes: 18 additions & 1 deletion .github/actions/setup-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,21 @@ runs:
- uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.scons-cache/
key: ${{ env.SCONS_PLATFORM }}${{ env.SCONS_PLATFORM_SUFFIX }}-main
key: ${{ env.SCONS_PLATFORM }}${{ env.SCONS_PLATFORM_SUFFIX }}-${{ env.GIT_BASE_REF }}-${{ github.ref }}-${{ github.sha }}

# We try to match an existing cache to restore from it. Each potential key is checked against
# all existing caches as a prefix. E.g. 'windows-x86_64' would match any cache that starts with
# "windows-x86_64", such as "windows-x86_64-master-refs/heads/master-6588a4a29af1621086feac0117d5d4d37af957fd".
#
# We check these prefixes in this order:
#
# 1. The exact match, including the base branch, the commit reference, and the SHA hash of the commit.
# 2. A partial match for the same base branch and the same commit reference.
# 3. A partial match for the same base branch and the base branch commit reference.
# 4. A partial match for the same base branch only (not ideal, matches any PR with the same base branch).

restore-keys: |
${{ env.SCONS_PLATFORM }}${{ env.SCONS_PLATFORM_SUFFIX }}-${{ env.GIT_BASE_REF }}-${{ github.ref }}-${{ github.sha }}
${{ env.SCONS_PLATFORM }}${{ env.SCONS_PLATFORM_SUFFIX }}-${{ env.GIT_BASE_REF }}-${{ github.ref }}
${{ env.SCONS_PLATFORM }}${{ env.SCONS_PLATFORM_SUFFIX }}-${{ env.GIT_BASE_REF }}-refs/heads/${{ env.GIT_BASE_REF }}
${{ env.SCONS_PLATFORM }}${{ env.SCONS_PLATFORM_SUFFIX }}-${{ env.GIT_BASE_REF }}
29 changes: 29 additions & 0 deletions .github/actions/update-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Update GitHub Release
description: Update the tag of an existing GH Release, and republish it.

inputs:
release-version:
required: true
republish:
default: false

runs:
using: "composite"
steps:
- name: Update the release tag
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
git tag -d ${{ inputs.release-version }}
git push origin :refs/tags/${{ inputs.release-version }}
git tag ${{ inputs.release-version }} ${{ git.sha }}
git push origin ${{ inputs.release-version }}
- name: Republish the release
if: ${{ inputs.republish }}
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release edit ${{ inputs.release-version }} --draft=false
40 changes: 40 additions & 0 deletions .github/workflows/build-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build and Test Pull Request

on:
pull_request:

# Make sure jobs cannot overlap.
concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:

# First, build the extension and upload the artifacts.

build-linux:
name: Compile and upload Linux version
uses: ./.github/workflows/extension-build-linux.yml

build-macos:
name: Compile and upload macOS version
uses: ./.github/workflows/extension-build-macos.yml

build-windows:
name: Compile and upload Windows version
uses: ./.github/workflows/extension-build-windows.yml

build-web:
name: Compile and upload Web version
uses: ./.github/workflows/extension-build-web.yml

build-android:
name: Compile and upload Android version
uses: ./.github/workflows/extension-build-android.yml

# Then, use the artifacts to test the example project.

export-example-project:
name: Export the example project for target platforms
needs: [ build-linux, build-macos, build-windows, build-web, build-android ]
uses: ./.github/workflows/example-export-project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Unstable (main branch)
name: Build and Publish Unstable (main branch)

on:
push:
Expand All @@ -7,7 +7,7 @@ on:

# Make sure jobs cannot overlap.
concurrency:
group: build-unstable-main
group: build-${{ github.ref }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -40,6 +40,8 @@ jobs:
name: Package and publish the extension
needs: [ build-linux, build-macos, build-windows, build-web, build-android ]
uses: ./.github/workflows/extension-publish-all.yml
with:
release-version: 'latest-unstable'

export-example-project:
name: Export the example project for target platforms
Expand All @@ -50,3 +52,19 @@ jobs:
name: Package and publish the example project
needs: [ export-example-project ]
uses: ./.github/workflows/example-publish-project.yml
with:
release-version: 'latest-unstable'

# Lastly, update the release tag and republish it.

release-all:
name: Update tag and re-release the GitHub Release
needs: [ publish-all, publish-example-project ]
runs-on: ubuntu-latest
steps:
- name: Update GitHub Release
uses: ./.github/actions/update-release
with:
release-version: 'latest-unstable'
republish: true

2 changes: 1 addition & 1 deletion .github/workflows/example-export-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

# Make sure jobs cannot overlap.
concurrency:
group: export-unstable-example-project
group: export-${{ github.ref }}-example-project
cancel-in-progress: true

env:
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/example-publish-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ name: Publish Example Project

on:
workflow_call:
inputs:
release-version:
required: true
type: string

# Make sure jobs cannot overlap.
concurrency:
group: publish-unstable-example-project
group: publish-${{ github.ref }}-example-project
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -41,11 +45,11 @@ jobs:
directory: example/export
split: true

- name: Update the rolling release with the example project
- name: Update the release with the example project
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release upload latest-unstable example/example-project-source.zip --clobber
gh release upload latest-unstable example/export/*.zip --clobber
gh release upload ${{ inputs.release-version }} example/example-project-source.zip --clobber
gh release upload ${{ inputs.release-version }} example/export/*.zip --clobber
3 changes: 2 additions & 1 deletion .github/workflows/extension-build-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

# Make sure jobs cannot overlap.
concurrency:
group: build-unstable-main-android
group: build-${{ github.ref }}-android
cancel-in-progress: true

jobs:
Expand All @@ -18,6 +18,7 @@ jobs:
name: Compile and upload Android (${{ matrix.arch }}) version
runs-on: ubuntu-latest
env:
GIT_BASE_REF: 'main'
SCONS_PLATFORM: android
SCONS_PLATFORM_SUFFIX: ".${{ matrix.arch }}"

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/extension-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ on:

# Make sure jobs cannot overlap.
concurrency:
group: build-unstable-main-linux
group: build-${{ github.ref }}-linux
cancel-in-progress: true

jobs:
build:
name: Compile and upload Linux version
runs-on: ubuntu-latest
env:
GIT_BASE_REF: 'main'
SCONS_PLATFORM: linux

steps:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/extension-build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ on:

# Make sure jobs cannot overlap.
concurrency:
group: build-unstable-main-macos
group: build-${{ github.ref }}-macos
cancel-in-progress: true

jobs:
build:
name: Compile and upload macOS version
runs-on: macos-latest
env:
GIT_BASE_REF: 'main'
SCONS_PLATFORM: macos

steps:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/extension-build-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ on:

# Make sure jobs cannot overlap.
concurrency:
group: build-unstable-main-web
group: build-${{ github.ref }}-web
cancel-in-progress: true

jobs:
build:
name: Compile and upload Web version
runs-on: ubuntu-latest
env:
GIT_BASE_REF: 'main'
SCONS_PLATFORM: web

steps:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/extension-build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

# Make sure jobs cannot overlap.
concurrency:
group: build-unstable-main-windows
group: build-${{ github.ref }}-windows
cancel-in-progress: true

jobs:
Expand All @@ -18,6 +18,7 @@ jobs:
name: Compile and upload Windows (${{ matrix.arch }}) version
runs-on: windows-latest
env:
GIT_BASE_REF: 'main'
SCONS_PLATFORM: windows
SCONS_PLATFORM_SUFFIX: ".${{ matrix.arch }}"

Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/extension-publish-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ name: Publish Extension

on:
workflow_call:
inputs:
release-version:
required: true
type: string

# Make sure jobs cannot overlap.
concurrency:
group: publish-unstable-main
group: publish-${{ github.ref }}
cancel-in-progress: true

jobs:
Expand Down Expand Up @@ -35,3 +39,4 @@ jobs:
directory: artifacts
path: bin
platform: ${{ matrix.platform }}
release-version: ${{ inputs.release-version }}

0 comments on commit 5a94078

Please sign in to comment.