Skip to content

Commit

Permalink
ci: Migrate to GitHub Actions and reusable workflows, part two (#117)
Browse files Browse the repository at this point in the history
### Motivation

Following #116 we can now cut over to the soundness checks from the
GithHub Actions CI and short-circuit the old CI checks.

### Modifications

- Remove most scripts used by old CI
- Short-circuit API checking script
- Short-circuit the docker CI
- Enable soundness tests in GitHub Actions workflow
- Ignore docker/* for license check
- Remove DocC plugin from package manifest
- Update CONTRIBUTING.md with instructions for local run

### Result

GitHub Actions CI is the one that we care about. We can then update the
branch rules, disable the old webhook, and, finally, remove the
vestigial stuff.
  • Loading branch information
simonjbeaumont authored Oct 2, 2024
1 parent e1f390a commit f795237
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 431 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ jobs:
name: Soundness
uses: apple/swift-nio/.github/workflows/soundness.yml@main
with:
# These are set to false to stage this in with the old CI.
# A follow-up PR will cut them over.
api_breakage_check_enabled: false
broken_symlink_check_enabled: false
docs_check_enabled: false
format_check_enabled: false
license_header_check_enabled: false
api_breakage_check_enabled: true
broken_symlink_check_enabled: true
docs_check_enabled: true
format_check_enabled: true
license_header_check_enabled: true
license_header_check_project_name: "SwiftOpenAPIGenerator"
shell_check_enabled: false
unacceptable_language_check_enabled: false
shell_check_enabled: true
unacceptable_language_check_enabled: true

unit-tests:
name: Unit tests
Expand Down
1 change: 1 addition & 0 deletions .licenseignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
**.md
**.txt
Package.swift
docker/*
40 changes: 26 additions & 14 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,40 @@ A good patch is:
3. Documented, adding API documentation as needed to cover new functions and properties.
4. Accompanied by a great commit message, using our commit message template.

### Run `./scripts/soundness.sh`
### Run CI checks locally

The scripts directory contains a [soundness.sh script](https://github.com/apple/swift-openapi-runtime/blob/main/scripts/soundness.sh)
that enforces additional checks, like license headers and formatting style.
You can run the Github Actions workflows locally using
[act](https://github.com/nektos/act). To run all the jobs that run on a pull
request, use the following command:

Please make sure to `./scripts/soundness.sh` before pushing a change upstream, otherwise it is likely the PR validation will fail
on minor changes such as a missing `self.` or similar formatting issues.
```
% act pull_request
```

For frequent contributors, we recommend adding the script as a [git pre-push hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks), which you can do via executing the following command in the project root directory:
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
```

```bash
cat << EOF > .git/hooks/pre-push
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:

if [[ -f "scripts/soundness.sh" ]]; then
scripts/soundness.sh
fi
EOF
```
% act --bind workflow_call -j soundness --input format_check_enabled=true
```

Which makes the script execute, and only allow the `git push` to complete if the check has passed.
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:

In the case of formatting issues, you can then `git add` the formatting changes, and attempt the push again.
```
--container-architecture=linux/amd64
--remote-name upstream
--action-offline-mode
```

## How to contribute your work

Expand Down
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(
Expand Down
8 changes: 4 additions & 4 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ services:

soundness:
<<: *common
command: /bin/bash -xcl "swift -version && uname -a && ./scripts/soundness.sh"
command: echo "skipping; moved to Github Actions"

test:
<<: *common
command: /bin/bash -xcl "swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-} $${STRICT_CONCURRENCY_ARG-}"
command: echo "skipping; moved to Github Actions"

shell:
<<: *common
entrypoint: /bin/bash

integration-test:
<<: *common
command: /bin/bash -xcl "swift -version && uname -a && bash ./scripts/run-integration-test.sh"
command: echo "skipping; moved to Github Actions"

docc-test:
<<: *common
command: /bin/bash -xcl "swift -version && uname -a && bash ./scripts/check-for-docc-warnings.sh"
command: echo "skipping; moved to Github Actions"
environment:
DOCC_TARGET: OpenAPIRuntime
28 changes: 1 addition & 27 deletions scripts/check-for-breaking-api-changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,4 @@
##
##===----------------------------------------------------------------------===##

set -euo pipefail

log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }

CURRENT_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_ROOT="$(git -C "${CURRENT_SCRIPT_DIR}" rev-parse --show-toplevel)"

log "Checking required environment variables..."
test -n "${BASELINE_REPO_URL:-}" || fatal "BASELINE_REPO_URL unset"
test -n "${BASELINE_TREEISH:-}" || fatal "BASELINE_TREEISH unset"

log "Fetching baseline: ${BASELINE_REPO_URL}#${BASELINE_TREEISH}..."
git -C "${REPO_ROOT}" fetch "${BASELINE_REPO_URL}" "${BASELINE_TREEISH}"
BASELINE_COMMIT=$(git -C "${REPO_ROOT}" rev-parse FETCH_HEAD)

log "Checking for API changes since ${BASELINE_REPO_URL}#${BASELINE_TREEISH} (${BASELINE_COMMIT})..."
swift package --package-path "${REPO_ROOT}" diagnose-api-breaking-changes \
"${BASELINE_COMMIT}" \
&& RC=$? || RC=$?

if [ "${RC}" -ne 0 ]; then
fatal "❌ Breaking API changes detected."
exit "${RC}"
fi
log "✅ No breaking API changes detected."
exit 0
37 changes: 0 additions & 37 deletions scripts/check-for-broken-symlinks.sh

This file was deleted.

40 changes: 0 additions & 40 deletions scripts/check-for-docc-warnings.sh

This file was deleted.

37 changes: 0 additions & 37 deletions scripts/check-for-unacceptable-language.sh

This file was deleted.

92 changes: 0 additions & 92 deletions scripts/check-license-headers.sh

This file was deleted.

Loading

0 comments on commit f795237

Please sign in to comment.