Skip to content

Commit 7f063dc

Browse files
CopilotSimplyDanny
andcommitted
Refactor workflows with YAML anchors for common patterns
Co-authored-by: SimplyDanny <[email protected]>
1 parent a46d100 commit 7f063dc

File tree

9 files changed

+122
-86
lines changed

9 files changed

+122
-86
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ on:
88
permissions:
99
contents: read
1010

11+
# Common reusable configurations
12+
x-checkout-step: &checkout-step
13+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
14+
with:
15+
persist-credentials: false
16+
1117
jobs:
1218
bazel_linux:
1319
name: Bazel, Linux, Swift 6.2 # pre-installed
1420
runs-on: ubuntu-24.04
1521
steps:
16-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
17-
with:
18-
persist-credentials: false
22+
- *checkout-step
1923
- uses: ./.github/actions/bazel-linux-build
2024
name: Build SwiftLint with Bazel
2125
env:
@@ -40,9 +44,7 @@ jobs:
4044
version: '6.2'
4145
container: ${{ matrix.image }}
4246
steps:
43-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
44-
with:
45-
persist-credentials: false
47+
- *checkout-step
4648
- name: Build plugins
4749
uses: ./.github/actions/run-make
4850
with:

.github/workflows/docker.yml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ on:
1515
required: true
1616
type: string
1717

18+
# Common reusable configurations
19+
x-checkout-step-pr: &checkout-step-pr
20+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
21+
if: needs.set-context.outputs.checkout-ref == 'pr'
22+
with:
23+
persist-credentials: false
24+
25+
x-checkout-step-ref: &checkout-step-ref
26+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
27+
if: needs.set-context.outputs.checkout-ref != 'pr'
28+
with:
29+
ref: ${{ needs.set-context.outputs.checkout-ref }}
30+
persist-credentials: false
31+
1832
jobs:
1933
set-context:
2034
name: Set Context
@@ -57,15 +71,8 @@ jobs:
5771
packages: write
5872
needs: set-context
5973
steps:
60-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
61-
if: needs.set-context.outputs.checkout-ref == 'pr'
62-
with:
63-
persist-credentials: false
64-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
65-
if: needs.set-context.outputs.checkout-ref != 'pr'
66-
with:
67-
ref: ${{ needs.set-context.outputs.checkout-ref }}
68-
persist-credentials: false
74+
- *checkout-step-pr
75+
- *checkout-step-ref
6976
- uses: ./.github/actions/docker-build
7077
with:
7178
platform: amd64
@@ -79,15 +86,8 @@ jobs:
7986
packages: write
8087
needs: set-context
8188
steps:
82-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
83-
if: needs.set-context.outputs.checkout-ref == 'pr'
84-
with:
85-
persist-credentials: false
86-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
87-
if: needs.set-context.outputs.checkout-ref != 'pr'
88-
with:
89-
ref: ${{ needs.set-context.outputs.checkout-ref }}
90-
persist-credentials: false
89+
- *checkout-step-pr
90+
- *checkout-step-ref
9191
- uses: ./.github/actions/docker-build
9292
with:
9393
platform: arm64

.github/workflows/docs.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,32 @@ on:
55
branches: [main]
66
pull_request:
77

8+
# Common reusable configurations
9+
x-checkout-step: &checkout-step
10+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
11+
with:
12+
persist-credentials: false
13+
14+
x-swift-version-step: &swift-version-step
15+
name: Get Swift version
16+
id: swift_version
17+
run: echo "version=$(swift --version | grep '[5-9]\.[0-9]\+\(\.[0-9]\)\?' -o | head -1)" >> "$GITHUB_OUTPUT"
18+
19+
x-cache-step-linux: &cache-step-linux
20+
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
21+
with:
22+
key: ${{ runner.os }}-spm-${{ steps.swift_version.outputs.version }}-${{ hashFiles('Package.resolved', 'Package.swift') }}
23+
restore-keys: ${{ runner.os }}-spm-${{ steps.swift_version.outputs.version }}-
24+
path: .build
25+
826
jobs:
927
create-docs:
1028
name: Create
1129
runs-on: ubuntu-24.04
1230
permissions:
1331
contents: read
1432
steps:
15-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
16-
with:
17-
persist-credentials: false
33+
- *checkout-step
1834
- uses: ruby/setup-ruby@ab177d40ee5483edb974554986f56b33477e21d0 # v1.265.0
1935
with:
2036
bundler-cache: true
@@ -24,14 +40,8 @@ jobs:
2440
target: "//:swiftlint @SourceKittenFramework//:sourcekitten"
2541
env:
2642
CI_BAZELRC_FILE_CONTENT: ${{ secrets.CI_BAZELRC_FILE_CONTENT }}
27-
- name: Get Swift version
28-
id: swift_version
29-
run: echo "version=$(swift --version | grep '[5-9]\.[0-9]\+\(\.[0-9]\)\?' -o | head -1)" >> "$GITHUB_OUTPUT"
30-
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
31-
with:
32-
key: ${{ runner.os }}-spm-${{ steps.swift_version.outputs.version }}-${{ hashFiles('Package.resolved', 'Package.swift') }}
33-
restore-keys: ${{ runner.os }}-spm-${{ steps.swift_version.outputs.version }}-
34-
path: .build
43+
- *swift-version-step
44+
- *cache-step-linux
3545
- name: Generate documentation
3646
run: |
3747
export PATH="/usr/share/swift/usr/bin:$PATH"

.github/workflows/lint.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ permissions:
77
contents: read
88
pull-requests: write
99

10+
# Common reusable configurations
11+
x-checkout-step: &checkout-step
12+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
13+
with:
14+
persist-credentials: false
15+
1016
jobs:
1117
lint-swift:
1218
name: Swift
1319
runs-on: ubuntu-24.04 # "Noble Numbat"
1420
steps:
15-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
16-
with:
17-
persist-credentials: false
21+
- *checkout-step
1822
- uses: ./.github/actions/bazel-linux-build
1923
name: Build SwiftLint with Bazel
2024
env:
@@ -25,9 +29,7 @@ jobs:
2529
name: Markdown
2630
runs-on: ubuntu-24.04
2731
steps:
28-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
29-
with:
30-
persist-credentials: false
32+
- *checkout-step
3133
- name: Lint
3234
uses: DavidAnson/markdownlint-cli2-action@992badcdf24e3b8eb7e87ff9287fe931bcb00c6e # v20.0.0
3335
with:
@@ -39,9 +41,7 @@ jobs:
3941
name: Actions
4042
runs-on: ubuntu-24.04
4143
steps:
42-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
43-
with:
44-
persist-credentials: false
44+
- *checkout-step
4545
- name: Register problem matcher
4646
run: |
4747
curl -sSL https://raw.githubusercontent.com/rhysd/actionlint/main/.github/actionlint-matcher.json > actionlint-matcher.json

.github/workflows/plugins-sync.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ on:
1111
permissions:
1212
contents: read
1313

14+
# Common reusable configurations
15+
x-checkout-step: &checkout-step
16+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
17+
with:
18+
persist-credentials: false
19+
1420
jobs:
1521
sync:
1622
name: Sync Plugins Folder
1723
runs-on: ubuntu-24.04
1824
steps:
1925
- name: Checkout repository
20-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
21-
with:
22-
persist-credentials: false
26+
<<: *checkout-step
2327
- name: Run file sync
2428
uses: BetaHuhn/repo-file-sync-action@8b92be3375cf1d1b0cd579af488a9255572e4619 # v1.21.1
2529
with:

.github/workflows/post-release.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ on:
44
release:
55
types: published
66

7+
# Common reusable configurations
8+
x-checkout-step: &checkout-step
9+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
10+
with:
11+
persist-credentials: false
12+
713
jobs:
814
setup-credentials:
915
name: Setup Actor Credentials
@@ -48,10 +54,9 @@ jobs:
4854
permissions:
4955
contents: read
5056
steps:
51-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
57+
- <<: *checkout-step
5258
with:
5359
ref: ${{ github.event.release.tag_name }}
54-
persist-credentials: false
5560
- name: Deploy to CocoaPods
5661
run: make pod_publish
5762
env:
@@ -66,10 +71,9 @@ jobs:
6671
contents: read
6772
steps:
6873
- name: Checkout repository
69-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
74+
<<: *checkout-step
7075
with:
7176
ref: ${{ github.event.release.tag_name }}
72-
persist-credentials: false
7377
- name: Parse checksum
7478
id: parse_checksum
7579
run: echo "checksum=$(grep -o '[a-fA-F0-9]\{64\}' Package.swift)" >> "$GITHUB_OUTPUT"

.github/workflows/release.yml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ env:
1616
DEVELOPER_DIR: /Applications/Xcode_26.0.1.app
1717
RELEASE_BRANCH: release/${{ inputs.version }}
1818

19+
# Common reusable configurations
20+
x-checkout-step: &checkout-step
21+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
22+
with:
23+
persist-credentials: false
24+
25+
x-checkout-release-branch: &checkout-release-branch
26+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
27+
with:
28+
ref: ${{ env.RELEASE_BRANCH }}
29+
persist-credentials: false
30+
31+
x-upload-artifact: &upload-artifact
32+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
33+
1934
jobs:
2035
setup-credentials:
2136
name: Setup Actor Credentials
@@ -69,9 +84,7 @@ jobs:
6984
contents: read
7085
steps:
7186
- name: Checkout repository
72-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
73-
with:
74-
persist-credentials: false
87+
<<: *checkout-step
7588
- name: Set up Ruby and Bundler
7689
uses: ruby/setup-ruby@ab177d40ee5483edb974554986f56b33477e21d0 # v1.265.0
7790
with:
@@ -103,16 +116,13 @@ jobs:
103116
permissions:
104117
contents: read
105118
steps:
106-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
107-
with:
108-
ref: ${{ env.RELEASE_BRANCH }}
109-
persist-credentials: false
119+
- <<: *checkout-release-branch
110120
- name: Install dependencies
111121
run: sudo apt-get install -y libcurl4-openssl-dev libxml2-dev
112122
- name: Build binary
113123
run: make --debug spm_linux_build
114124
- name: Upload binary
115-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
125+
<<: *upload-artifact
116126
with:
117127
name: ${{ matrix.artifact_name }}
118128
path: .build/release/swiftlint
@@ -138,10 +148,7 @@ jobs:
138148
env:
139149
BINARY_PATH: .build/${{ matrix.swift_sdk }}/release/swiftlint
140150
steps:
141-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
142-
with:
143-
ref: ${{ env.RELEASE_BRANCH }}
144-
persist-credentials: false
151+
- <<: *checkout-release-branch
145152
- name: Install SDK
146153
run: swift sdk install https://download.swift.org/swift-6.2-release/static-sdk/swift-6.2-RELEASE/swift-6.2-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum d2225840e592389ca517bbf71652f7003dbf45ac35d1e57d98b9250368769378
147154
- name: Build static binary
@@ -155,7 +162,7 @@ jobs:
155162
- name: Strip binary
156163
run: strip -s "$BINARY_PATH"
157164
- name: Upload artifact
158-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
165+
<<: *upload-artifact
159166
with:
160167
name: ${{ matrix.artifact_name }}
161168
path: ${{ env.BINARY_PATH }}
@@ -167,14 +174,11 @@ jobs:
167174
permissions:
168175
contents: read
169176
steps:
170-
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
171-
with:
172-
ref: ${{ env.RELEASE_BRANCH }}
173-
persist-credentials: false
177+
- <<: *checkout-release-branch
174178
- name: Build SwiftLint for macOS
175179
run: make --debug bazel_release
176180
- name: Upload build artifacts
177-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
181+
<<: *upload-artifact
178182
with:
179183
name: swiftlint-macos
180184
path: |

.github/workflows/stale-issues.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ on:
88
permissions:
99
issues: write
1010

11+
# Common reusable configurations
12+
x-checkout-step: &checkout-step
13+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
14+
with:
15+
persist-credentials: false
16+
1117
jobs:
1218
close-stale-issues:
1319
runs-on: ubuntu-latest
1420
steps:
1521
- name: Checkout repository
16-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
17-
with:
18-
persist-credentials: false
22+
<<: *checkout-step
1923
- name: Mark or close stale issues
2024
run: |
2125
./tools/stale-issues.rb ${{ github.repository }}

0 commit comments

Comments
 (0)