Skip to content

Commit 2265b38

Browse files
committed
wip
1 parent 88ab1fe commit 2265b38

File tree

2 files changed

+83
-2
lines changed

2 files changed

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

0 commit comments

Comments
 (0)