Skip to content

ci: update Swift version to #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/actions/install-swift/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ runs:
- name: Install Swiftly
shell: bash
run: |
UNAME=$(uname -m)

export SWIFTLY_HOME_DIR="$HOME/.local/share/swiftly"
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $GITHUB_ENV
echo "SWIFTLY_HOME_DIR=$SWIFTLY_HOME_DIR" >> $HOME/.bashrc
Expand All @@ -26,6 +24,7 @@ runs:
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $GITHUB_ENV
echo "SWIFTLY_BIN_DIR=$SWIFTLY_BIN_DIR" >> $HOME/.bashrc

UNAME=$(uname -m)
curl -O "https://download.swift.org/swiftly/linux/swiftly-$UNAME.tar.gz"
tar zxf "swiftly-$UNAME.tar.gz"
./swiftly init \
Expand Down
86 changes: 86 additions & 0 deletions .github/workflows/update-swift-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Update Swift Version

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
schedule:
- cron: '0 0 */14 * *' # Every 14 days at midnight UTC
workflow_dispatch:

jobs:
update-swift-version:
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Git
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"

- name: Install dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y curl jq

- name: Create or update branch
id: latest
run: |
BRANCH=ci/update-swift-version
git checkout -B "$BRANCH"

UNAME=$(uname -m)
curl -O "https://download.swift.org/swiftly/linux/swiftly-$UNAME.tar.gz"
tar zxf "swiftly-$UNAME.tar.gz"
./swiftly init \
--skip-install \
--assume-yes \
--quiet-shell-followup \
--no-modify-profile
. "$HOME/.local/share/swiftly/env.sh"

latest=$(swiftly list-available main-snapshot | grep main-snapshot | head -n 1 | awk '{print $1}')
echo -n "$latest" > .swift-version
if [[ -z "$(git status --porcelain .swift-version)" ]]; then
echo "No changes. Exiting."
exit 78 # neutral exit status
fi

git add .swift-version
git commit -m "Update Swift version to $latest"
git push -u origin "$BRANCH"

- name: Create or update PR
id: find-pr
run: |
gh auth setup-git
pr_number=$(gh pr list --head ci/update-swift-version --state open --json number --jq '.[0]')

TITLE="ci: update Swift version to ${{ steps.latest.outputs.version }}"
BODY="This PR updates the \`.swift-version\` file to Swift ${{ steps.latest.outputs.version }}.

> This PR was automatically generated."

if [[ -z "$pr_number" ]]; then
gh pr create \
--title "$TITLE" \
--body "$BODY" \
--head "ci/update-swift-version" \
--base "main"
else
echo "PR already exists: #$pr_number"
gh pr edit $pr_number --title "$TITLE" --body "$BODY"
fi

gh pr merge $pr_number --auto --squash

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
main-snapshot-2025-04-12
main-snapshot-2025-04-30