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