Skip to content

Commit fb90531

Browse files
committed
Refactor workflows with YAML anchors for common patterns
1 parent c6daedc commit fb90531

8 files changed

Lines changed: 68 additions & 88 deletions

File tree

.github/workflows/build.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313
name: Bazel, Linux, Swift 6.2 # pre-installed
1414
runs-on: ubuntu-24.04
1515
steps:
16-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
16+
- &checkout-step
17+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
1718
with:
1819
persist-credentials: false
1920
- uses: ./.github/actions/bazel-linux-build
@@ -40,9 +41,7 @@ jobs:
4041
version: '6.2'
4142
container: ${{ matrix.image }}
4243
steps:
43-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
44-
with:
45-
persist-credentials: false
44+
- *checkout-step
4645
- name: Build plugins
4746
uses: ./.github/actions/run-make
4847
with:

.github/workflows/docker.yml

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@ jobs:
2525
docker-tag: ${{ steps.vars.outputs.docker-tag }}
2626
repository-lc: ${{ steps.vars.outputs.repository-lc }}
2727
steps:
28-
- name: Define variables
29-
id: vars
30-
run: |
31-
if [[ "${{ github.event_name }}" == "push" ]]; then
32-
{
33-
echo "checkout-ref=main"
34-
echo "docker-tag=latest"
35-
} >> "$GITHUB_OUTPUT"
36-
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
37-
{
38-
echo "checkout-ref=pr"
39-
echo "docker-tag=pr-${{ github.event.pull_request.number }}"
40-
} >> "$GITHUB_OUTPUT"
41-
else
42-
{
43-
echo "checkout-ref=${INPUTS_TAG}"
44-
echo "docker-tag=${INPUTS_TAG}"
45-
} >> "$GITHUB_OUTPUT"
46-
fi
47-
echo "repository-lc=${REPOSITORY,,}" >> "$GITHUB_OUTPUT"
48-
env:
49-
REPOSITORY: ${{ github.repository }}
50-
INPUTS_TAG: ${{ inputs.tag }}
28+
- name: Define variables
29+
id: vars
30+
run: |
31+
if [[ "${{ github.event_name }}" == "push" ]]; then
32+
{
33+
echo "checkout-ref=main"
34+
echo "docker-tag=latest"
35+
} >> "$GITHUB_OUTPUT"
36+
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
37+
{
38+
echo "checkout-ref=pr"
39+
echo "docker-tag=pr-${{ github.event.pull_request.number }}"
40+
} >> "$GITHUB_OUTPUT"
41+
else
42+
{
43+
echo "checkout-ref=${INPUTS_TAG}"
44+
echo "docker-tag=${INPUTS_TAG}"
45+
} >> "$GITHUB_OUTPUT"
46+
fi
47+
echo "repository-lc=${REPOSITORY,,}" >> "$GITHUB_OUTPUT"
48+
env:
49+
REPOSITORY: ${{ github.repository }}
50+
INPUTS_TAG: ${{ inputs.tag }}
5151

5252
build-amd64:
5353
name: Build AMD64 Image
@@ -57,19 +57,21 @@ jobs:
5757
packages: write
5858
needs: set-context
5959
steps:
60-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
61-
if: needs.set-context.outputs.checkout-ref == 'pr'
62-
with:
63-
persist-credentials: false
64-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
65-
if: needs.set-context.outputs.checkout-ref != 'pr'
66-
with:
67-
ref: ${{ needs.set-context.outputs.checkout-ref }}
68-
persist-credentials: false
69-
- uses: ./.github/actions/docker-build
70-
with:
71-
platform: amd64
72-
token: ${{ secrets.GITHUB_TOKEN }}
60+
- &checkout-step-pr
61+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
62+
if: needs.set-context.outputs.checkout-ref == 'pr'
63+
with:
64+
persist-credentials: false
65+
- &checkout-step-ref
66+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
67+
if: needs.set-context.outputs.checkout-ref != 'pr'
68+
with:
69+
ref: ${{ needs.set-context.outputs.checkout-ref }}
70+
persist-credentials: false
71+
- uses: ./.github/actions/docker-build
72+
with:
73+
platform: amd64
74+
token: ${{ secrets.GITHUB_TOKEN }}
7375

7476
build-arm64:
7577
name: Build ARM64 Image
@@ -79,19 +81,12 @@ jobs:
7981
packages: write
8082
needs: set-context
8183
steps:
82-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
83-
if: needs.set-context.outputs.checkout-ref == 'pr'
84-
with:
85-
persist-credentials: false
86-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
87-
if: needs.set-context.outputs.checkout-ref != 'pr'
88-
with:
89-
ref: ${{ needs.set-context.outputs.checkout-ref }}
90-
persist-credentials: false
91-
- uses: ./.github/actions/docker-build
92-
with:
93-
platform: arm64
94-
token: ${{ secrets.GITHUB_TOKEN }}
84+
- *checkout-step-pr
85+
- *checkout-step-ref
86+
- uses: ./.github/actions/docker-build
87+
with:
88+
platform: arm64
89+
token: ${{ secrets.GITHUB_TOKEN }}
9590

9691
merge:
9792
name: Create Multi-Platform Image

.github/workflows/lint.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ jobs:
1212
name: Swift
1313
runs-on: ubuntu-24.04 # "Noble Numbat"
1414
steps:
15-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
15+
- &checkout-step
16+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
1617
with:
1718
persist-credentials: false
1819
- uses: ./.github/actions/bazel-linux-build
@@ -25,9 +26,7 @@ jobs:
2526
name: Markdown
2627
runs-on: ubuntu-slim
2728
steps:
28-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
29-
with:
30-
persist-credentials: false
29+
- *checkout-step
3130
- name: Lint
3231
uses: DavidAnson/markdownlint-cli2-action@07035fd053f7be764496c0f8d8f9f41f98305101 # v22.0.0
3332
with:
@@ -39,9 +38,7 @@ jobs:
3938
name: Actions
4039
runs-on: ubuntu-24.04
4140
steps:
42-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
43-
with:
44-
persist-credentials: false
41+
- *checkout-step
4542
- name: Register problem matcher
4643
run: |
4744
curl -sSL https://raw.githubusercontent.com/rhysd/actionlint/main/.github/actionlint-matcher.json > actionlint-matcher.json

.github/workflows/plugins-sync.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ jobs:
1616
name: Sync Plugins Folder
1717
runs-on: ubuntu-slim
1818
steps:
19-
- name: Checkout repository
20-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
19+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2120
with:
2221
persist-credentials: false
2322
- name: Run file sync

.github/workflows/post-release.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ jobs:
4848
permissions:
4949
contents: read
5050
steps:
51-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
51+
- &checkout-step
52+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
5253
with:
5354
ref: ${{ github.event.release.tag_name }}
5455
persist-credentials: false
@@ -65,11 +66,7 @@ jobs:
6566
permissions:
6667
contents: read
6768
steps:
68-
- name: Checkout repository
69-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
70-
with:
71-
ref: ${{ github.event.release.tag_name }}
72-
persist-credentials: false
69+
- *checkout-step
7370
- name: Parse checksum
7471
id: parse_checksum
7572
run: echo "checksum=$(grep -o '[a-fA-F0-9]\{64\}' Package.swift)" >> "$GITHUB_OUTPUT"

.github/workflows/release.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ jobs:
3434
permissions:
3535
contents: write
3636
steps:
37-
- name: Checkout repository
38-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
37+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
3938
with:
4039
persist-credentials: true
4140
- name: Checkout or create release branch
@@ -71,8 +70,7 @@ jobs:
7170
env:
7271
DEVELOPER_DIR: /Applications/Xcode_15.0.1.app # Supports iOS 17.0 simulator selected by CocoaPods.
7372
steps:
74-
- name: Checkout repository
75-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
73+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
7674
with:
7775
persist-credentials: false
7876
- name: Set up Ruby and Bundler
@@ -103,8 +101,11 @@ jobs:
103101
artifact_name: swiftlint-linux-arm64
104102
permissions:
105103
contents: read
104+
env:
105+
BINARY_PATH: .build/release/swiftlint
106106
steps:
107-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
107+
- &checkout-release-branch
108+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
108109
with:
109110
ref: ${{ env.RELEASE_BRANCH }}
110111
persist-credentials: false
@@ -116,7 +117,7 @@ jobs:
116117
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
117118
with:
118119
name: ${{ matrix.artifact_name }}
119-
path: .build/release/swiftlint
120+
path: ${{ env.BINARY_PATH }}
120121

121122
build-static-linux:
122123
name: Build Static Linux ${{ matrix.arch }} Binary
@@ -139,10 +140,7 @@ jobs:
139140
env:
140141
BINARY_PATH: .build/${{ matrix.swift_sdk }}/release/swiftlint
141142
steps:
142-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
143-
with:
144-
ref: ${{ env.RELEASE_BRANCH }}
145-
persist-credentials: false
143+
- *checkout-release-branch
146144
- name: Install SDK
147145
run: swift sdk install https://download.swift.org/swift-6.2.3-release/static-sdk/swift-6.2.3-RELEASE/swift-6.2.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum f30ec724d824ef43b5546e02ca06a8682dafab4b26a99fbb0e858c347e507a2c
148146
- name: Build mimalloc object
@@ -188,10 +186,7 @@ jobs:
188186
permissions:
189187
contents: read
190188
steps:
191-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
192-
with:
193-
ref: ${{ env.RELEASE_BRANCH }}
194-
persist-credentials: false
189+
- *checkout-release-branch
195190
- name: Build SwiftLint for macOS
196191
run: make --debug bazel_release
197192
- name: Upload build artifacts

.github/workflows/stale-issues.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ jobs:
1212
close-stale-issues:
1313
runs-on: ubuntu-24.04
1414
steps:
15-
- name: Checkout repository
16-
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
15+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
1716
with:
1817
persist-credentials: false
1918
- name: Mark or close stale issues

.github/workflows/test.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ jobs:
1717
runs-on: ubuntu-24.04
1818
container: swift:6.2-noble
1919
steps:
20-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
20+
- &checkout-step
21+
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2122
with:
2223
persist-credentials: false
2324
- name: Get Swift version
@@ -48,9 +49,7 @@ jobs:
4849
env:
4950
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app
5051
steps:
51-
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
52-
with:
53-
persist-credentials: false
52+
- *checkout-step
5453
- uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
5554
with:
5655
key: macos-${{ matrix.macOS }}-xcode-spm-${{ matrix.xcode }}-${{ hashFiles('Package.resolved', 'Package.swift') }}

0 commit comments

Comments
 (0)