Skip to content

🔒 Pin GitHub Actions to commit SHAs #332

🔒 Pin GitHub Actions to commit SHAs

🔒 Pin GitHub Actions to commit SHAs #332

Workflow file for this run

name: CI
on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
jobs:
test:
name: Test (macOS)
# Skip fork PRs — they can't access the secrets this reusable workflow needs.
# Runs on push, workflow_dispatch, and same-repo PRs.
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
uses: huggingface/hf-workflows/.github/workflows/swift_transformers_unit_tests.yml@a88e7fa2eaee28de5a4d6142381b1fb792349b67 # main
with:
# Use the PR merge ref, not the head.
pr_number: ${{ github.event.pull_request.number }}
secrets:
HF_HUB_READ_TOKEN: ${{ secrets.HF_HUB_READ_TOKEN }}
test-linux:
name: Test (Linux)${{ matrix.traits != '' && format(' with --traits {0}', matrix.traits) || '' }}
runs-on: ubuntu-latest
container: swift:${{ matrix.swift }}
strategy:
fail-fast: false
matrix:
include:
- swift: "6.2.3"
traits: ""
- swift: "6.2.3"
traits: "Xet"
steps:
- name: Checkout PR merge ref if called from PR
if: ${{ github.event.pull_request.number }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
fetch-depth: 0
- name: Checkout fallback
if: ${{ !github.event.pull_request.number }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Cache Swift Package Manager dependencies
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5
with:
path: ~/.cache/org.swift.swiftpm
key: ${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'xet-off' || 'xet-on' }}-spm-${{ hashFiles('Package*.swift') }}-${{ hashFiles('Package.resolved') }}
restore-keys: |
${{ runner.os }}-swift-${{ matrix.swift }}-${{ matrix.traits == '' && 'xet-off' || 'xet-on' }}-spm-
- name: Build
run: swift build${{ matrix.traits != '' && format(' --traits {0}', matrix.traits) || '' }}
- name: Run tests
env:
CI_DISABLE_NETWORK_MONITOR: "1"
# Skip test targets that use URLSession on Linux due to a
# FoundationNetworking race condition that crashes during teardown.
# See: https://github.com/swiftlang/swift-corelibs-foundation/issues/3675
run: |
swift test --skip HubTests --skip TokenizersTests${{ matrix.traits != '' && format(' --traits {0}', matrix.traits) || '' }}
lint:
name: Lint
runs-on: macos-latest
steps:
- name: Checkout PR merge ref if called from PR
if: ${{ github.event.pull_request.number }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
fetch-depth: 0
- name: Checkout fallback
if: ${{ !github.event.pull_request.number }}
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- run: |
swift format lint --strict --recursive .
- name: Suggest fixes (if check fails)
if: failure()
run: |
echo "### Here's how to fix the formatting locally:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo "# Format all Swift files" >> $GITHUB_STEP_SUMMARY
echo 'swift format -i --recursive .' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY