diff --git a/.github/actions/install-swift/action.yml b/.github/actions/install-swift/action.yml index 2c88c24..dc7924a 100644 --- a/.github/actions/install-swift/action.yml +++ b/.github/actions/install-swift/action.yml @@ -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 @@ -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 \ diff --git a/.github/workflows/update-swift-version.yml b/.github/workflows/update-swift-version.yml new file mode 100644 index 0000000..ffbedae --- /dev/null +++ b/.github/workflows/update-swift-version.yml @@ -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 "github-actions@users.noreply.github.com" + + - 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 }} diff --git a/.swift-version b/.swift-version index 79c018b..1ce3e67 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -main-snapshot-2025-04-12 +main-snapshot-2025-04-30 \ No newline at end of file