Update Swift Version #51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Swift Version | |
on: | |
schedule: | |
- cron: '0 0 */14 * *' # Every 14 days at midnight UTC | |
workflow_dispatch: | |
jobs: | |
update-swift-version: | |
name: Create or update PR | |
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: Open pull request if needed | |
id: update | |
run: | | |
set -ex | |
git fetch | |
branch=ci/update-swift-version | |
if git ls-remote --exit-code --heads origin "$branch"; then | |
git checkout -b "$branch" --track "origin/$branch" | |
else | |
git checkout -b "$branch" | |
fi | |
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" | |
swift_version=".swift-version" | |
latest=$(swiftly list-available main-snapshot | grep main-snapshot | head -n 1 | awk '{print $1}') | |
echo -n "$latest" > "$swift_version" | |
echo "version=$latest" >> "$GITHUB_OUTPUT" | |
title="Update to $latest" | |
body="Updates the \`.swift-version\` file to Swift \`$latest\`. | |
> This PR was automatically generated." | |
if [[ -n "$(git status --porcelain "$swift_version")" ]]; then | |
git add "$swift_version" | |
git commit -m "$title" -m "$body" | |
git push -u origin "$branch" | |
fi | |
pr=$(gh pr list --head "$branch" --state open --json number --jq '.[0].number') | |
if [[ -z "$pr" ]]; then | |
gh pr create \ | |
--title "$title" \ | |
--body "$body" \ | |
--head "$branch" \ | |
--base "main" \ | |
--draft | |
else | |
gh pr edit \ | |
--title "$title" \ | |
--body "$body" | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |