Skip to content

Commit f7def2f

Browse files
committed
wip
1 parent b227f1d commit f7def2f

File tree

2 files changed

+90
-2
lines changed

2 files changed

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

0 commit comments

Comments
 (0)