Skip to content
Closed
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions .github/changed-files.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# We lack a convenient means of gathering *all* the changes when specializations are passed, so
# a catch-all variable is the easiest workaround.
everything:
- "**"

# Determines if build actions should occur after static checks are ran. Broadly speaking, these
# files changing would result in SCons rebuilding the engine, or are otherwise pertinent to the
# buildsystem itself.
sources:
- .github/{actions/*,workflows}/*.yml
- "**/{SConstruct,SCsub,*.py}"
- "**/*.{hpp,cpp,inc}"
- scripts
- deps/**
- tests/**

# Determines which files are appropriate for running clangd-tidy checks on.
clangd:
- "**/*.{hpp,cpp,inc}"
207 changes: 84 additions & 123 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,91 @@
name: 🖥️ Builds

on: [push, pull_request, merge_group]

env:
GH_BASE_BRANCH: master
on:
push:
branches: ['master']
paths:
- ".github/workflows/{builds, master-builds}.yml"
- "**/{SConstruct,SCsub,*.py}"
- "**/*.{hpp,cpp,inc}"
- "scripts"
- "deps/**"
- "tests/**"
- "AUTHORS.md"
- "COPYRIGHT"
- "LICENSE.md"
- ".pre-commit-config.yaml"
- "pyproject.toml"
- ".clang-format"
- ".clang-tidy"
- ".gitmodules"
pull_request:
branches: ['**']
paths:
- ".github/workflows/{builds, master-builds}.yml"
- "**/{SConstruct,SCsub,*.py}"
- "**/*.{hpp,cpp,inc}"
- "scripts"
- "deps/**"
- "tests/**"
- "AUTHORS.md"
- "COPYRIGHT"
- "LICENSE.md"
- ".pre-commit-config.yaml"
- "pyproject.toml"
- ".clang-format"
- ".clang-tidy"
- ".gitmodules"
merge_group:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}|${{ github.ref_name }}
cancel-in-progress: true
group: ${{ github.workflow }}|${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions: {}

jobs:
static-checks:
static-checks-builds:
name: Code style, file formatting, and docs
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
if: github.run_attempt > 1 || github.event_name == 'workflow_dispatch' || !vars.DISABLE_SIM_BUILDS
outputs:
changed-files: '"${{ steps.changed-files.outputs.clangd_all_changed_files }}"' # Wrap with quotes to bookend internal quote separators.
sources-changed: ${{ steps.changed-files.outputs.sources_any_changed }}
steps:
- name: Checkout project
uses: actions/checkout@v4.1.1
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 2
fetch-depth: 0 # Treeless clone. Slightly less performant than a shallow clone, but makes finding diffs instantaneous.
filter: tree:0 # See: https://github.blog/open-source/git/get-up-to-speed-with-partial-clone-and-shallow-clone/

- name: Install APT dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
uses: awalsh128/cache-apt-pkgs-action@acb598e5ddbc6f68a970c5da0688d2f3a9f04d05 # v1.6.0
with:
packages: libxml2-utils

- name: Get changed files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config diff.wsErrorHighlight all
if [ "${{ github.event_name }}" == "pull_request" -o "${{ github.event.forced }}" == "true" -o "${{ github.event.created }}" == "true" ]; then
files=$(git diff-tree --no-commit-id --name-only -r HEAD^1..HEAD 2> /dev/null || true)
elif [ "${{ github.event_name }}" == "push" -a "${{ github.event.created }}" == "false" ]; then
files=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.before }}..${{ github.event.after }} 2> /dev/null || true)
fi
echo "$files" >> changed.txt
cat changed.txt
files=$(echo "$files" | xargs -I {} sh -c 'echo "\"./{}\""' | tr '\n' ' ')
echo "CHANGED_FILES=$files" >> $GITHUB_ENV

- name: Style checks via pre-commit
uses: pre-commit/action@v3.0.1
id: changed-files
uses: tj-actions/changed-files@9426d40962ed5378910ee2e21d5f8c6fcbf2dd96 # v47.0.6
with:
extra_args: --files ${{ env.CHANGED_FILES }}
safe_output: false # Output passed to environment variable to avoid command injection.
separator: '" "' # To account for paths with spaces, ensure our items are split by quotes internally.
skip_initial_fetch: true
files_yaml_from_source_file: .github/changed-files.yml

build:
runs-on: ${{matrix.os}}
name: ${{matrix.name}}
needs: static-checks
permissions: write-all
- name: Style checks via prek
uses: j178/prek-action@bdca6f102f98e2b4c7029491a53dfd366469e33d # v2.0.4
env:
CHANGED_FILES: '"${{ steps.changed-files.outputs.everything_all_changed_files }}"' # Wrap with quotes to bookend internal quote separators
with:
extra-args: --files ${{ env.CHANGED_FILES }}

build-master:
name: ${{ matrix.name }}
needs: static-checks-builds
if: needs.static-checks-builds.outputs.sources-changed == 'true' || github.event_name != 'pull_request'
permissions:
contents: read
strategy:
fail-fast: false
matrix:
Expand All @@ -59,31 +96,36 @@ jobs:
target: template_debug
platform: windows
arch: x86_64

- identifier: windows-release
os: windows-latest
name: 🏁 Windows Release
target: template_release
platform: windows
arch: x86_64

- identifier: macos-debug
os: macos-latest
name: 🍎 macOS (universal) Debug
target: template_debug
platform: macos
arch: universal

- identifier: macos-release
os: macos-latest
name: 🍎 macOS (universal) Release
target: template_release
platform: macos
arch: universal

- identifier: linux-debug
os: ubuntu-latest
name: 🐧 Linux Debug
runner: ubuntu-20.04
target: template_debug
platform: linux
arch: x86_64

- identifier: linux-release
os: ubuntu-latest
name: 🐧 Linux Release
Expand All @@ -92,93 +134,12 @@ jobs:
platform: linux
arch: x86_64

steps:
- name: Checkout project
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup build cache
uses: OpenVicProject/openvic-cache@master
with:
cache-name: ${{ matrix.identifier }}
base-branch: ${{ env.GH_BASE_BRANCH }}
continue-on-error: true

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Set up SCons
shell: bash
run: |
python -c "import sys; print(sys.version)"
python -m pip install scons
scons --version

- name: Linux dependencies
if: ${{ matrix.platform == 'linux' }}
run: |
sudo apt-get update -qq
sudo apt-get install -qqq build-essential pkg-config libtbb-dev
g++ --version
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 12
sudo update-alternatives --set g++ /usr/bin/g++-12
g++ --version

- name: Compile with SCons
uses: OpenVicProject/openvic-build@master
with:
platform: ${{ matrix.platform }}
target: ${{ matrix.target }}
sconsflags: arch=${{ matrix.arch }} build_ovsim_library=yes run_ovsim_tests=yes build_ovsim_benchmarks=yes

- name: Delete compilation files
if: ${{ matrix.platform == 'windows' }}
run: |
Remove-Item bin/* -Include *.exp,*.pdb -Force

- name: Upload library artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-${{ matrix.identifier }}-library
path: |
${{ github.workspace }}/bin/libopenvic-simulation.*

- name: Upload executable artifact
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-${{ matrix.identifier }}-executable
path: |
${{ github.workspace }}/bin/openvic-simulation.headless.*

- name: Archive Release
uses: thedoctor0/zip-release@0.7.6
with:
type: "zip"
filename: "../../../libopenvic-simulation.${{ matrix.platform }}.${{ matrix.arch }}.zip"
directory: "${{ github.workspace }}/bin/"
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

- name: Create and upload asset
uses: ncipollo/release-action@v1.13.0
with:
allowUpdates: true
artifacts: "libopenvic-simulation.${{ matrix.platform }}.${{ matrix.arch }}.zip"
omitNameDuringUpdate: true
omitBodyDuringUpdate: true
token: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

merge-library-files:
runs-on: ubuntu-latest
needs: build
name: 📚 Merge Library Files
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
delete-merged: true
name: ${{ github.event.repository.name }}-library
pattern: ${{ github.event.repository.name }}-*-library
uses: ./.github/workflows/reusable-build.yml
with:
identifier: ${{ matrix.identifier }}
os: ${{ matrix.runner || matrix.os }}
name: ${{ matrix.name }}
target: ${{ matrix.target }}
platform: ${{ matrix.platform }}
arch: ${{ matrix.arch }}
merge-library-files: true
88 changes: 88 additions & 0 deletions .github/workflows/nightly-releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: 🌘 Nightly Releases
on:
schedule:
- cron: '23 0 * * *'
workflow_dispatch:

env:
TARGET_REPO: OpenVic-Simulation-nightly-builds

permissions: {}

jobs:
check-nightly:
name: Check for new commits
if: github.event_name == 'workflow_dispatch' || !vars.DISABLE_SIM_NIGHTLYS
permissions:
contents: read
runs-on: ubuntu-latest
outputs:
commit: ${{ steps.check_for_new_commits.outputs.commit }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
persist-credentials: false

- name: Retrieve HEAD commit hash
id: head
shell: bash
run: echo "head=$(git rev-parse HEAD)" | tee -a "${GITHUB_OUTPUT}"

- name: Cache nightly commit hash
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
env:
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 1
with:
path: .nightly_commit_hash
key: release-nightly-${{ steps.head.outputs.head }}
restore-keys: |
release-nightly-

- name: Check for new commits
id: check_for_new_commits
shell: bash
run: |
relevant_files=(
"deps/*"
"misc/*"
"scripts"
"src/*.hpp"
"src/*.cpp"
':!src/openvic-simulation/pch.hpp'
':!src/openvic-simulation/pch.cpp'
"pyproject.toml"
"SConstruct"
".github/workflows/builds.yml"
".github/workflows/nightly-builds.yml"
)
if [[ -f .nightly_commit_hash ]]; then
limit_args=(
"$(cat .nightly_commit_hash)..HEAD"
)
else
limit_args=(
--since="24 hours ago"
)
fi
echo "commit=$(git log --format=%H -1 "${limit_args[@]}" -- "${relevant_files[@]}")" | tee -a "${GITHUB_OUTPUT}"

- name: Record new nightly commit hash
env:
HEAD: ${{ steps.head.outputs.head }}
shell: bash
run: echo "${HEAD}" | tee .nightly_commit_hash

nightly-release:
name: Publish GitHub release
needs: check-nightly
if: needs.check-nightly.outputs.commit
permissions:
contents: write # May be needed to publish release
id-token: write # Needed for trusted publishing
uses: ./.github/workflows/reusable-release.yml
with:
prerelease: true
target: ${{ github.env.TARGET_REPO }}
scons-flags: 'use_hot_reload=no build_ovsim_tests=no debug_symbols=yes'

17 changes: 17 additions & 0 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: 🖥️ Releases

on:
push:
tags: ["**"]

permissions: {}

jobs:
release:
name: Publish GitHub release
permissions:
contents: write # May be needed to publish release
id-token: write # Needed for trusted publishing
uses: ./.github/workflows/reusable-release.yml
with:
prerelease: ${{ contains('["alpha", "beta", "rc", "snapshot"]', github.ref) }}
Loading