custom format configuration #137
Workflow file for this run
This file contains 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
# This workflow will build a Swift project | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift | |
name: Swift CQ | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
versions: | |
runs-on: ubuntu-latest | |
outputs: | |
swift-image: ${{ steps.swift-image.outputs.version }} | |
swift-format: ${{ steps.swift-format.outputs.version }} | |
steps: | |
- name: swift | |
id: swift-image | |
run: echo "version=6.0-noble" >> $GITHUB_OUTPUT | |
- name: swift-format | |
id: swift-format | |
run: echo "version=600.0.0" >> $GITHUB_OUTPUT | |
install-swift-format: | |
needs: versions | |
runs-on: ubuntu-latest | |
container: swift:${{ needs.versions.outputs.swift-image }} | |
steps: | |
- name: Restore build cache | |
uses: actions/cache@v4 | |
id: cache | |
with: | |
path: ./vendor/swift-format/.build | |
key: ${{ runner.os }}-swift-format-${{ needs.versions.outputs.swift-format }} | |
- name: Checkout apple/swift-format | |
if: steps.cache.outputs.cache-hit != 'true' | |
uses: actions/checkout@v4 | |
with: | |
repository: apple/swift-format | |
ref: ${{ needs.versions.outputs.swift-format }} | |
path: vendor/swift-format | |
- name: Build swift-format | |
if: steps.cache.outputs.cache-hit != 'true' | |
working-directory: ./vendor/swift-format | |
run: | | |
swift package resolve | |
swift build -c release | |
echo "${PWD}/.build/release" >> $GITHUB_PATH | |
lint: | |
needs: [versions, install-swift-format] | |
runs-on: ubuntu-latest | |
container: | |
image: swift:${{ needs.versions.outputs.swift-image }} | |
volumes: | |
- /usr/bin/curl:/usr/bin/curl | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Restore build cache | |
uses: actions/cache@v4 | |
with: | |
path: ./vendor/swift-format/.build | |
key: ${{ runner.os }}-swift-format-${{ needs.versions.outputs.swift-format }} | |
- name: Install swift-format | |
run: | | |
echo "${PWD}/vendor/swift-format/.build/release" >> $GITHUB_PATH | |
- uses: reviewdog/action-setup@v1 | |
with: | |
reviewdog_version: latest | |
- uses: haya14busa/action-cond@v1 | |
id: reporter | |
with: | |
cond: ${{ github.event_name == 'pull_request' }} | |
if_true: "github-pr-review" | |
if_false: "github-check" | |
- uses: haya14busa/action-cond@v1 | |
id: filter-mode | |
with: | |
cond: ${{ github.event_name == 'pull_request' }} | |
if_true: "file" | |
if_false: "nofilter" | |
- name: Run swift-format lint with reviewdog | |
env: | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }} | |
run: | | |
reviewdog -reporter=${{ steps.reporter.outputs.value }} -runners=swift-format-lint -filter-mode=${{ steps.filter-mode.outputs.value }} -fail-on-error | |
format: | |
needs: [versions, install-swift-format] | |
runs-on: ubuntu-latest | |
container: | |
image: swift:${{ needs.versions.outputs.swift-image }} | |
volumes: | |
- /usr/bin/curl:/usr/bin/curl | |
if: github.event_name == 'pull_request' | |
permissions: | |
contents: read | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Restore build cache | |
uses: actions/cache@v4 | |
with: | |
path: ./vendor/swift-format/.build | |
key: ${{ runner.os }}-swift-format-${{ needs.versions.outputs.swift-format }} | |
- name: Install swift-format | |
run: | | |
echo "${PWD}/vendor/swift-format/.build/release" >> $GITHUB_PATH | |
- name: Run format | |
run: swift format -ipr Sources/ Package.swift | |
- run: ls -a | |
- run: git status | |
- name: Reviewdog suggester / mix format | |
uses: reviewdog/action-suggester@v1 | |
with: | |
tool_name: swift-format | |
filter_mode: file | |
fail_on_error: true |