Skip to content

Commit 08b7ebe

Browse files
chore: update global workflows (#25)
1 parent 4501c7b commit 08b7ebe

File tree

4 files changed

+91
-41
lines changed

4 files changed

+91
-41
lines changed

.github/workflows/codeql.yml

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
---
2-
# This action is centrally managed in https://github.com/<organization>/.github/
2+
# This workflow is centrally managed in https://github.com/<organization>/.github/
33
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
44
# the above-mentioned repo.
55

66
# This workflow will analyze all supported languages in the repository using CodeQL Analysis.
77

88
name: "CodeQL"
9+
permissions:
10+
contents: read
911

1012
on:
1113
push:
12-
branches: ["master"]
14+
branches:
15+
- master
1316
pull_request:
14-
branches: ["master"]
17+
branches:
18+
- master
1519
schedule:
1620
- cron: '00 12 * * 0' # every Sunday at 12:00 UTC
1721

@@ -22,14 +26,17 @@ concurrency:
2226
jobs:
2327
languages:
2428
name: Get language matrix
25-
runs-on: ubuntu-latest
2629
outputs:
2730
matrix: ${{ steps.lang.outputs.result }}
2831
continue: ${{ steps.continue.outputs.result }}
32+
runs-on: ubuntu-latest
2933
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
3037
- name: Get repo languages
31-
uses: actions/github-script@v7
3238
id: lang
39+
uses: actions/github-script@v7
3340
with:
3441
script: |
3542
// CodeQL supports ['cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift']
@@ -51,32 +58,62 @@ jobs:
5158
"include": []
5259
}
5360
61+
// Track languages we've already added to avoid duplicates
62+
const addedLanguages = new Set()
63+
64+
// Check if workflow files exist to determine if we should add actions language
65+
const fs = require('fs');
66+
const hasYmlFiles = fs.existsSync('.github/workflows') &&
67+
fs.readdirSync('.github/workflows').some(file => file.endsWith('.yml') || file.endsWith('.yaml'));
68+
69+
// Add actions language if workflow files exist
70+
if (hasYmlFiles) {
71+
console.log('Found GitHub Actions workflow files. Adding actions to the matrix.');
72+
matrix['include'].push({
73+
"category": "/language:actions",
74+
"language": "actions",
75+
"name": "actions",
76+
"os": "ubuntu-latest"
77+
});
78+
}
79+
5480
for (let [key, value] of Object.entries(response.data)) {
5581
// remap language
5682
if (remap_languages[key.toLowerCase()]) {
5783
console.log(`Remapping language: ${key} to ${remap_languages[key.toLowerCase()]}`)
5884
key = remap_languages[key.toLowerCase()]
5985
}
60-
if (supported_languages.includes(key.toLowerCase())) {
61-
console.log(`Found supported language: ${key}`)
86+
87+
const normalizedKey = key.toLowerCase()
88+
89+
if (supported_languages.includes(normalizedKey) && !addedLanguages.has(normalizedKey)) {
90+
// Mark this language as added
91+
addedLanguages.add(normalizedKey)
92+
93+
console.log(`Found supported language: ${normalizedKey}`)
6294
let osList = ['ubuntu-latest'];
63-
if (key.toLowerCase() === 'swift') {
95+
if (normalizedKey === 'swift') {
6496
osList = ['macos-latest'];
65-
} else if (key.toLowerCase() === 'cpp') {
66-
// TODO: update macos to latest after the below issue is resolved
67-
// https://github.com/github/codeql-action/issues/2266
68-
osList = ['macos-13', 'ubuntu-latest', 'windows-latest'];
97+
} else if (normalizedKey === 'cpp') {
98+
osList = ['macos-latest', 'ubuntu-latest', 'windows-latest'];
6999
}
70100
for (let os of osList) {
71101
// set name for matrix
72-
if (osList.length == 1) {
73-
name = key.toLowerCase()
74-
} else {
75-
name = `${key.toLowerCase()}, ${os}`
102+
let name = osList.length === 1 ? normalizedKey : `${normalizedKey}, ${os}`
103+
104+
// set category for matrix
105+
let category = `/language:${normalizedKey}`
106+
if (normalizedKey === 'cpp') {
107+
category = `/language:cpp-${os.split('-')[0]}`
76108
}
77109
78110
// add to matrix
79-
matrix['include'].push({"language": key.toLowerCase(), "os": os, "name": name})
111+
matrix['include'].push({
112+
"category": category,
113+
"language": normalizedKey,
114+
"name": name,
115+
"os": os
116+
})
80117
}
81118
}
82119
}
@@ -87,8 +124,8 @@ jobs:
87124
return matrix
88125
89126
- name: Continue
90-
uses: actions/github-script@v7
91127
id: continue
128+
uses: actions/github-script@v7
92129
with:
93130
script: |
94131
// if matrix['include'] is an empty list return false, otherwise true
@@ -102,24 +139,22 @@ jobs:
102139
103140
analyze:
104141
name: Analyze (${{ matrix.name }})
105-
if: ${{ needs.languages.outputs.continue == 'true' }}
142+
if: needs.languages.outputs.continue == 'true'
106143
defaults:
107144
run:
108145
shell: ${{ matrix.os == 'windows-latest' && 'msys2 {0}' || 'bash' }}
109146
env:
110147
GITHUB_CODEQL_BUILD: true
111-
needs: [languages]
112-
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
113-
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
148+
needs: languages
114149
permissions:
115150
actions: read
116151
contents: read
117152
security-events: write
118-
153+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
119154
strategy:
120155
fail-fast: false
121156
matrix: ${{ fromJson(needs.languages.outputs.matrix) }}
122-
157+
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
123158
steps:
124159
- name: Maximize build space
125160
if: >-
@@ -167,8 +202,7 @@ jobs:
167202
- third-party
168203
169204
# Pre autobuild
170-
# create a file named .codeql-prebuild-${{ matrix.language }}.sh in the root of your repository
171-
# create a file named .codeql-build-${{ matrix.language }}.sh in the root of your repository
205+
# create a file named .codeql-prebuild-${{ matrix.language }}-${{ runner.os }}.sh in the root of your repository
172206
- name: Prebuild
173207
id: prebuild
174208
run: |
@@ -187,7 +221,7 @@ jobs:
187221
- name: Perform CodeQL Analysis
188222
uses: github/codeql-action/analyze@v3
189223
with:
190-
category: "/language:${{matrix.language}}"
224+
category: "${{ matrix.category }}"
191225
output: sarif-results
192226
upload: failure-only
193227

@@ -204,11 +238,13 @@ jobs:
204238
- name: Upload SARIF
205239
uses: github/codeql-action/upload-sarif@v3
206240
with:
241+
category: "${{ matrix.category }}"
207242
sarif_file: sarif-results/${{ matrix.language }}.sarif
208243

209244
- name: Upload loc as a Build Artifact
210245
uses: actions/upload-artifact@v4
211246
with:
212247
name: sarif-results-${{ matrix.language }}-${{ runner.os }}
213248
path: sarif-results
249+
if-no-files-found: error
214250
retention-days: 1

.github/workflows/common-lint.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
---
2-
# This action is centrally managed in https://github.com/<organization>/.github/
2+
# This workflow is centrally managed in https://github.com/<organization>/.github/
33
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
44
# the above-mentioned repo.
55

66
# Common linting.
77

88
name: common lint
9+
permissions:
10+
contents: read
911

1012
on:
1113
pull_request:
12-
branches: [master]
13-
types: [opened, synchronize, reopened]
14+
branches:
15+
- master
16+
types:
17+
- opened
18+
- synchronize
19+
- reopened
1420

1521
concurrency:
1622
group: "${{ github.workflow }}-${{ github.ref }}"
@@ -77,9 +83,10 @@ jobs:
7783
7884
- name: C++ - Clang format lint
7985
if: always() && steps.cpp_files.outputs.found_files
80-
uses: DoozyX/clang-format-lint-action@v0.18
86+
uses: DoozyX/clang-format-lint-action@v0.20
8187
with:
8288
source: ${{ steps.cpp_files.outputs.found_files }}
89+
clangFormatVersion: '20'
8390
extensions: 'c,cpp,h,hpp,m,mm'
8491
style: file
8592
inplace: false
@@ -263,5 +270,4 @@ jobs:
263270

264271
- name: YAML - log
265272
if: always() && steps.yamllint.outcome == 'failure'
266-
run: |
267-
cat "${{ steps.yamllint.outputs.logfile }}" >> $GITHUB_STEP_SUMMARY
273+
run: cat "${{ steps.yamllint.outputs.logfile }}" >> $GITHUB_STEP_SUMMARY

.github/workflows/issues.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
---
2-
# This action is centrally managed in https://github.com/<organization>/.github/
2+
# This workflow is centrally managed in https://github.com/<organization>/.github/
33
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
44
# the above-mentioned repo.
55

66
# Label and un-label actions using `../label-actions.yml`.
77

88
name: Issues
9+
permissions: {}
910

1011
on:
1112
issues:
12-
types: [labeled, unlabeled]
13+
types:
14+
- labeled
15+
- unlabeled
1316
discussion:
14-
types: [labeled, unlabeled]
17+
types:
18+
- labeled
19+
- unlabeled
1520

1621
jobs:
1722
label:

.github/workflows/update-docs.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
---
2-
# This action is centrally managed in https://github.com/<organization>/.github/
2+
# This workflow is centrally managed in https://github.com/<organization>/.github/
33
# Don't make changes to this file in this repo as they will be overwritten with changes made to the same file in
44
# the above-mentioned repo.
55

6-
# Use the `rtd` repository label to identify repositories that should trigger have this workflow.
6+
# To use, add the `rtd` repository label to identify repositories that should trigger this workflow.
77
# If the project slug is not the repository name, add a repository variable named `READTHEDOCS_SLUG` with the value of
88
# the ReadTheDocs project slug.
99

1010
# Update readthedocs on release events.
1111

1212
name: Update docs
13+
permissions: {}
1314

1415
on:
1516
release:
16-
types: [created, edited, deleted]
17+
types:
18+
- created
19+
- edited
20+
- deleted
1721

1822
concurrency:
1923
group: "${{ github.workflow }}-${{ github.event.release.tag_name }}"
@@ -73,8 +77,7 @@ jobs:
7377
- name: Update RTD project
7478
# changing the default branch in readthedocs makes "latest" point to that branch/tag
7579
# we can also update other properties like description, etc.
76-
if: >-
77-
steps.check.outputs.isLatestRelease == 'true'
80+
if: steps.check.outputs.isLatestRelease == 'true'
7881
run: |
7982
json_body=$(jq -n \
8083
--arg default_branch "${TAG}" \

0 commit comments

Comments
 (0)