|
| 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