Skip to content

Commit 0d16cd1

Browse files
tibbonflibitijibibo
authored andcommitted
feat(ci): Enhance GitHub Actions workflow
- Update actions/checkout to v4 - Add build caching for macOS and Linux jobs - Implement concurrency control to cancel redundant runs - Restrict GITHUB_TOKEN permissions for security These changes improve CI performance, stability, and security.
1 parent 902acdd commit 0d16cd1

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ on:
2020
- "third_party/**"
2121
- ".github/workflows/ci.yml"
2222

23+
permissions:
24+
contents: read
25+
statuses: write
26+
27+
concurrency:
28+
group: ${{ github.workflow }}-${{ github.ref }}
29+
cancel-in-progress: true
30+
2331
env:
2432
SRC_DIR_PATH: desktop_version
2533

@@ -32,19 +40,42 @@ jobs:
3240
env:
3341
CXXFLAGS: -I/usr/local/include/SDL2
3442
LDFLAGS: -L/usr/local/lib
43+
HOMEBREW_NO_ENV_HINTS: 1 # Suppress brew update hints
3544

3645
steps:
37-
- uses: actions/checkout@v1
46+
- uses: actions/checkout@v4
3847
with:
3948
submodules: true
4049

50+
- name: Cache Homebrew packages
51+
id: cache-brew
52+
uses: actions/cache@v3
53+
with:
54+
path: |
55+
/usr/local/Cellar/ninja
56+
/usr/local/Cellar/sdl2
57+
/usr/local/opt/sdl2 # Symlink often used
58+
key: ${{ runner.os }}-brew-${{ hashFiles('/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/ninja.rb', '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/sdl2.rb') }} # Using hash of formula files if available, or a fixed key for simplicity if not easily determined
59+
4160
- name: Install dependencies
61+
if: steps.cache-brew.outputs.cache-hit != 'true'
4262
run: brew install ninja sdl2
4363

64+
- name: Cache CMake build folder
65+
id: cache-cmake-build
66+
uses: actions/cache@v3
67+
with:
68+
path: ${{ env.SRC_DIR_PATH }}/build
69+
key: ${{ runner.os }}-${{ env.container_image_tag }}-cmake-build-${{ hashFiles(format('{0}/CMakeLists.txt', env.SRC_DIR_PATH)) }}
70+
# Using a more specific key including a reference to the container if possible
71+
# We need to define container_image_tag in the env or find a way to get it
72+
4473
- name: CMake configure (default version)
4574
run: |
46-
mkdir ${SRC_DIR_PATH}/build && cd ${SRC_DIR_PATH}/build
47-
cmake -GNinja ..
75+
mkdir -p ${SRC_DIR_PATH}/build && cd ${SRC_DIR_PATH}/build
76+
# If cache was hit and build dir exists, this cmake might just verify.
77+
# If build dir is empty, it will configure.
78+
cmake -G Ninja ..
4879
- name: Build (default version)
4980
run: ninja -C ${SRC_DIR_PATH}/build
5081

@@ -68,15 +99,27 @@ jobs:
6899

69100
runs-on: ubuntu-latest
70101
container: registry.gitlab.steamos.cloud/steamrt/sniper/sdk:beta
102+
env:
103+
CONTAINER_IMAGE_TAG: beta
71104

72105
steps:
73106
- uses: actions/checkout@v4
74107
with:
75108
submodules: true
76109

110+
- name: Cache CMake build folder
111+
id: cache-cmake-build
112+
uses: actions/cache@v3
113+
with:
114+
path: ${{ env.SRC_DIR_PATH }}/build
115+
key: ${{ runner.os }}-${{ env.CONTAINER_IMAGE_TAG }}-cmake-build-${{ hashFiles(format('{0}/CMakeLists.txt', env.SRC_DIR_PATH)) }}
116+
# Using a more specific key including a reference to the container
117+
77118
- name: CMake configure (default version)
78119
run: |
79-
mkdir ${SRC_DIR_PATH}/build && cd ${SRC_DIR_PATH}/build
120+
mkdir -p ${SRC_DIR_PATH}/build && cd ${SRC_DIR_PATH}/build
121+
# If cache was hit and build dir exists, this cmake might just verify.
122+
# If build dir is empty, it will configure.
80123
cmake -G Ninja ..
81124
- name: Build (default version)
82125
run: ninja -C ${SRC_DIR_PATH}/build
@@ -104,7 +147,7 @@ jobs:
104147
SDL_VERSION: 2.26.0
105148

106149
steps:
107-
- uses: actions/checkout@v1
150+
- uses: actions/checkout@v4
108151
with:
109152
submodules: true
110153

0 commit comments

Comments
 (0)