Skip to content

Commit 0782001

Browse files
authored
feat(ci): add scheduled workflow to update clang-format and swiftlint (#5047)
1 parent 92d1dc2 commit 0782001

File tree

6 files changed

+141
-14
lines changed

6 files changed

+141
-14
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# This workflow is used to update the custom tooling versions for the project.
2+
#
3+
# We prefer to use Dependabot to update external dependencies, but at this time it does not include Homebrew as a supported package manager (https://docs.github.com/en/code-security/dependabot/ecosystems-supported-by-dependabot/supported-ecosystems-and-repositories).
4+
# Furthermore, neither `swiftlint` nor `clang-format` are listed as dependencies in our repository, therefore also not picked up by Dependabot.
5+
#
6+
# Therefore we are using a custom workflow to update relevant files and open a pull request with the changes.
7+
8+
name: "Automation: Update tooling versions"
9+
10+
on:
11+
schedule:
12+
- cron: "0 0 * * *"
13+
workflow_dispatch:
14+
15+
# Permissions configuration:
16+
# - 'contents: write' is required to allow the workflow to commit changes to the repository
17+
# when updating the tooling version files and creating branches for pull requests.
18+
# - 'pull-requests: write' is required to allow the workflow to create pull requests
19+
# using the peter-evans/create-pull-request action when tooling version updates are available.
20+
permissions:
21+
contents: write
22+
pull-requests: write
23+
24+
# Concurrency configuration:
25+
# - We use a named concurrency group to prevent multiple instances of this workflow from running
26+
# simultaneously, which could lead to race conditions when creating branches and pull requests.
27+
# Since this workflow modifies version files and creates PRs, concurrent runs could interfere
28+
# with each other, resulting in conflicting branches or duplicate PRs.
29+
# - We enable cancellation of in-progress runs because only the most recent run matters for
30+
# version updates. There's no value in completing outdated runs, especially for scheduled
31+
# workflows that might queue up overnight. This approach conserves GitHub Actions minutes
32+
# and ensures we're always working with the latest repository state.
33+
concurrency:
34+
group: "auto-update-tools"
35+
cancel-in-progress: true
36+
37+
jobs:
38+
auto-update-tools:
39+
runs-on: macos-15
40+
steps:
41+
- name: Checkout Repository
42+
uses: actions/checkout@v4
43+
44+
- name: Update Homebrew
45+
run: brew update
46+
47+
- name: Install CI tools
48+
run: |
49+
make init-ci-format
50+
51+
- name: Update tooling versions
52+
run: make update-versions
53+
54+
- name: Check tooling versions
55+
run: make check-versions
56+
57+
- name: Print git status and changes
58+
run: |
59+
git status
60+
git diff HEAD
61+
62+
- name: Create pull request for clang-format version
63+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e #v7.0.8
64+
with:
65+
add-paths: scripts/.clang-format-version
66+
branch: github-actions/auto-update-tools-clang-format
67+
commit-message: "chore(deps): Update clang-format version"
68+
delete-branch: true
69+
title: "chore(deps): Update clang-format version"
70+
sign-commits: true
71+
base: main
72+
73+
- name: Create pull request for swiftlint version
74+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e #v7.0.8
75+
with:
76+
add-paths: scripts/.swiftlint-version
77+
branch: github-actions/auto-update-tools-swiftlint
78+
commit-message: "chore(deps): Update swiftlint version"
79+
delete-branch: true
80+
title: "chore(deps): Update swiftlint version"
81+
sign-commits: true
82+
base: main

.github/workflows/format-code.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@ name: format code
22
on:
33
pull_request:
44
paths:
5-
- 'Sources/**'
6-
- 'Tests/**'
7-
- 'test-server/**'
8-
- 'Samples/**'
9-
- '.github/workflows/format-code.yml'
5+
- "Sources/**"
6+
- "Tests/**"
7+
- "test-server/**"
8+
- "Samples/**"
9+
- ".github/workflows/format-code.yml"
1010

1111
jobs:
1212
# Formats Swift, Objective-C, C++, and C code and commits the formatted code
1313
# if necessary
1414
format-code:
1515
name: Format Code
16-
runs-on: macos-13
16+
runs-on: macos-15
1717
steps:
1818
- uses: actions/checkout@v4
19-
## Update internal list of formulae to the latest
20-
- run: brew update
21-
- name: Install Clang-Format
22-
run: brew install clang-format
19+
20+
- name: Install tooling
21+
run: make init-ci-format
22+
2323
- run: swiftlint --version
2424
- uses: actions/setup-node@v4
2525
with:
2626
node-version-file: .nvmrc
2727
- run: corepack enable
2828
- run: yarn install
29+
2930
- name: Format Code
3031
run: make format
3132

Brewfile-ci-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
brew 'clang-format'
2+
brew 'swiftlint'
3+
brew 'rbenv'

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ init:
66
rbenv install --skip-existing
77
rbenv exec gem update bundler
88
rbenv exec bundle install
9-
clang-format --version | awk '{print $$3}' > scripts/.clang-format-version
10-
swiftlint version > scripts/.swiftlint-version
9+
./scripts/update-tooling-versions.sh
1110

1211
# The node version manager is optional, so we don't fail if it's not installed.
1312
if [ -n "$NVM_DIR" ] && [ -d "$NVM_DIR" ]; then nvm use; fi
@@ -24,6 +23,16 @@ init-ci-test:
2423
init-ci-deploy:
2524
brew bundle --file Brewfile-ci-deploy
2625

26+
# installs the tools needed to run CI format tasks locally
27+
.PHONY: init-ci-format
28+
init-ci-format:
29+
brew bundle --file Brewfile-ci-format
30+
rbenv install --skip-existing
31+
32+
.PHONY: update-versions
33+
update-versions:
34+
./scripts/update-tooling-versions.sh
35+
2736
.PHONY: check-versions
2837
check-versions:
2938
./scripts/check-tooling-versions.sh

scripts/check-tooling-versions.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
#!/usr/bin/env bash
22

3-
REMOTE_CLANG_FORMAT_VERSION=$(cat scripts/.clang-format-version)
3+
set -euo pipefail
4+
5+
# Store current working directory
6+
pushd "$(pwd)" > /dev/null
7+
# Change to script directory
8+
cd "${0%/*}"
9+
10+
# -- Begin Script --
11+
12+
REMOTE_CLANG_FORMAT_VERSION=$(cat .clang-format-version)
413
LOCAL_CLANG_FORMAT_VERSION=$(clang-format --version | awk '{print $3}')
514

6-
REMOTE_SWIFTLINT_VERSION=$(cat scripts/.swiftlint-version)
15+
REMOTE_SWIFTLINT_VERSION=$(cat .swiftlint-version)
716
LOCAL_SWIFTLINT_VERSION=$(swiftlint version)
817

918
RESOLUTION_MESSAGE="Please run \`make init\` to update your local dev tools. This may actually upgrade to a newer version than what is currently recorded in repo; if that happens, please commit the update to the any lockfiles etc as well."
@@ -29,3 +38,8 @@ if [ $SENTRY_TOOLING_UP_TO_DATE == false ]; then
2938
echo "${RESOLUTION_MESSAGE}"
3039
exit 1
3140
fi
41+
42+
# -- End Script --
43+
44+
# Return to original working directory
45+
popd > /dev/null

scripts/update-tooling-versions.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Store current working directory
6+
pushd "$(pwd)" > /dev/null
7+
# Change to script directory
8+
cd "${0%/*}"
9+
10+
# -- Begin Script --
11+
12+
clang-format --version | awk '{print $3}' > .clang-format-version
13+
swiftlint version > .swiftlint-version
14+
15+
# -- End Script --
16+
17+
# Return to original working directory
18+
popd > /dev/null

0 commit comments

Comments
 (0)