Skip to content

Commit 06cac28

Browse files
authored
Add workflow to auto-update .swift-version (#111)
Not yet complete workflow which automatically updates the `.swift-version` file in this repo.
1 parent b227f1d commit 06cac28

File tree

9 files changed

+95
-23
lines changed

9 files changed

+95
-23
lines changed

.github/actions/install-swift/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ runs:
1616
- name: Install Swiftly
1717
shell: bash
1818
run: |
19-
UNAME=$(uname -m)
20-
2119
export SWIFTLY_HOME_DIR="$HOME/.local/share/swiftly"
2220
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $GITHUB_ENV
2321
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $HOME/.bashrc
@@ -26,6 +24,7 @@ runs:
2624
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $GITHUB_ENV
2725
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $HOME/.bashrc
2826
27+
UNAME=$(uname -m)
2928
curl -O "https://download.swift.org/swiftly/linux/swiftly-$UNAME.tar.gz"
3029
tar zxf "swiftly-$UNAME.tar.gz"
3130
./swiftly init \

.github/workflows/build-esp.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ on:
44
push:
55
branches: ["main"]
66
pull_request:
7-
types: [opened, reopened, synchronize]
8-
repository_dispatch:
9-
types: [create-pull-request]
7+
types: [opened, reopened, synchronize, ready_for_review]
108

119
jobs:
1210
build-esp:

.github/workflows/build-nuttx.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ on:
44
push:
55
branches: ["main"]
66
pull_request:
7-
types: [opened, reopened, synchronize]
8-
repository_dispatch:
9-
types: [create-pull-request]
7+
types: [opened, reopened, synchronize, ready_for_review]
108

119
jobs:
1210
build-nuttx:

.github/workflows/build-pico-sdk.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ on:
44
push:
55
branches: ["main"]
66
pull_request:
7-
types: [opened, reopened, synchronize]
8-
repository_dispatch:
9-
types: [create-pull-request]
7+
types: [opened, reopened, synchronize, ready_for_review]
108

119
jobs:
1210
build-pico-sdk:

.github/workflows/build-rpi-baremetal.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ on:
44
push:
55
branches: ["main"]
66
pull_request:
7-
types: [opened, reopened, synchronize]
8-
repository_dispatch:
9-
types: [create-pull-request]
7+
types: [opened, reopened, synchronize, ready_for_review]
108

119
jobs:
1210
build-rpi-baremetal:

.github/workflows/build-stm.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ on:
44
push:
55
branches: ["main"]
66
pull_request:
7-
types: [opened, reopened, synchronize]
8-
repository_dispatch:
9-
types: [create-pull-request]
7+
types: [opened, reopened, synchronize, ready_for_review]
108

119
jobs:
1210
build-stm32:

.github/workflows/build-zephyr.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ on:
44
push:
55
branches: ["main"]
66
pull_request:
7-
types: [opened, reopened, synchronize]
8-
repository_dispatch:
9-
types: [create-pull-request]
7+
types: [opened, reopened, synchronize, ready_for_review]
108

119
jobs:
1210
build-zephyr:

.github/workflows/lint.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ on:
44
push:
55
branches: ["main"]
66
pull_request:
7-
types: [opened, reopened, synchronize]
8-
repository_dispatch:
9-
types: [create-pull-request]
7+
types: [opened, reopened, synchronize, ready_for_review]
108

119
jobs:
1210
validate_format_config:
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Update Swift Version
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
schedule:
7+
- cron: '0 0 */14 * *' # Every 14 days at midnight UTC
8+
workflow_dispatch:
9+
10+
jobs:
11+
update-swift-version:
12+
name: Create or update PR
13+
runs-on: ubuntu-latest
14+
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Git
24+
run: |
25+
git config --global user.name "github-actions"
26+
git config --global user.email "[email protected]"
27+
28+
- name: Install dependencies
29+
run: |
30+
sudo apt-get update -qq
31+
sudo apt-get install -y curl jq
32+
33+
- name: Open pull request if needed
34+
id: update
35+
run: |
36+
set -ex
37+
38+
git fetch
39+
branch=ci/update-swift-version
40+
if git ls-remote --exit-code --heads origin "$branch"; then
41+
git checkout -b "$branch" --track "origin/$branch"
42+
else
43+
git checkout -b "$branch"
44+
fi
45+
46+
uname=$(uname -m)
47+
curl -O "https://download.swift.org/swiftly/linux/swiftly-$uname.tar.gz"
48+
tar zxf "swiftly-$uname.tar.gz"
49+
./swiftly init \
50+
--skip-install \
51+
--assume-yes \
52+
--quiet-shell-followup \
53+
--no-modify-profile
54+
. "$HOME/.local/share/swiftly/env.sh"
55+
56+
swift_version=".swift-version"
57+
latest=$(swiftly list-available main-snapshot | grep main-snapshot | head -n 1 | awk '{print $1}')
58+
echo -n "$latest" > "$swift_version"
59+
echo "version=$latest" >> "$GITHUB_OUTPUT"
60+
61+
title="Update to $latest"
62+
body="Updates the \`.swift-version\` file to Swift \`$latest\`.
63+
64+
> This PR was automatically generated."
65+
66+
if [[ -n "$(git status --porcelain "$swift_version")" ]]; then
67+
git add "$swift_version"
68+
git commit -m "$title" -m "$body"
69+
git push -u origin "$branch"
70+
fi
71+
72+
pr=$(gh pr list --head "$branch" --state open --json number --jq '.[0].number')
73+
if [[ -z "$pr" ]]; then
74+
gh pr create \
75+
--title "$title" \
76+
--body "$body" \
77+
--head "$branch" \
78+
--base "main" \
79+
--draft
80+
else
81+
gh pr edit \
82+
--title "$title" \
83+
--body "$body"
84+
fi
85+
86+
env:
87+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)