/github-workflows

Primary LanguagePythonApache License 2.0Apache-2.0

GitHub Actions Workflows

This repository will contain reusable workflows to minimize redundant workflows across the organization. This effort will also facilitate the standardization of testing processes while empowering repository code owners to customize their testing plans as needed. The repository will contain workflows to support different types of repositories, such as Swift Package and Swift Compiler.

For more details on reusable workflows, please refer to the Reusing workflows section in the GitHub Docs.

Reusable workflow for Swift package repositories

There are different kinds of workflows that this repository offers:

Soundness

The soundness workflows provides a multitude of checks to ensure a repository is following the best practices. By default each check is enabled but can be disabled by passing the appropriate workflow input. We recommend to adopt all soundness checks and enforce them on each PR.

A recommended workflow looks like this:

name: Pull request

on:
  pull_request:
    types: [opened, reopened, synchronize]

jobs:
  soundness:
    name: Soundness
    uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
    with:
      license_header_check_project_name: "Swift.org"

Testing

To enable pull request testing for all supported Swift versions (5.8, 5.9, 5.10, 6.0, and nightly) on Linux, add the following code example in .github/workflows/pull_request.yml:

name: pull_request

on:
  pull_request:
    types: [opened, reopened, synchronize]

jobs:
  tests:
    name: tests
    uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main

If your package only supports newer compiler versions, you can exclude older versions by using the exclude_swift_versions workflow input:

exclude_swift_versions: "[{\"swift_version\": \"5.8\"}]"

Additionally, if your package requires additional installed packages, you can use the pre_build_command:

pre_build_command: "apt-get update -y -q && apt-get install -y -q example"

macOS and Windows platform support will be available soon.

Running workflows locally

You can run the Github Actions workflows locally using act. To run all the jobs that run on a pull request, use the following command:

% act pull_request

To run just a single job, use workflow_call -j <job>, and specify the inputs the job expects. For example, to run just shellcheck:

% act workflow_call -j soundness --input shell_check_enabled=true

To bind-mount the working directory to the container, rather than a copy, use --bind. For example, to run just the formatting, and have the results reflected in your working directory:

% act --bind workflow_call -j soundness --input format_check_enabled=true

If you'd like act to always run with certain flags, these can be be placed in an .actrc file either in the current working directory or your home directory, for example:

--container-architecture=linux/amd64
--remote-name upstream
--action-offline-mode