This repository contains a reusable workflow and various bash scripts designed to streamline tasks in a Swift project.
The workflow utilizes the official swiftlang/github-workflows to perform checks and run Swift tests on the repository.
No installation required.
To use the workflow in a repository, simply copy the sample_actions.yml file into the .github/workflows directory within the repository. For more configuration options, refer to the official swiftlang/github-workflows repository.
A Makefile is included in this repository to simplify script execution. Copy it to the repository’s root directory where the scripts will be used.
This script runs a check for any breaking changes in the API. It uses the swift package diagnose-api-breaking-changes command to analyze the current API against the last tagged version and reports any breaking changes found.
Usage: make breakage
This script runs a search to find and report broken symbolic links within the repository. It iterates over all files tracked by Git and checks if their symlink targets exist.
Usage: make symlinks
This script executes Swift Package Manager’s documentation generation with the --warnings-as-errors flag to ensure that any documentation warnings are treated as errors, maintaining high-quality documentation standards.
Usage: make docc-warnings
Verifies that all source files contain the appropriate license headers, ensuring compliance with licensing requirements.
Usage: make license-header
This script checks for local Swift package dependencies in the repository. It scans Package.swift files for local dependencies defined using .package(path:) and reports any occurrences.
Usage: make deps
This script runs a security analysis on the OpenAPI specification using OWASP ZAP. It runs the zap-api-scan.py script inside a Docker container to check for security vulnerabilities in the OpenAPI definition.
Usage: make openapi-security
This script validates the OpenAPI specification for compliance with the OpenAPI standard. It uses the openapi-spec-validator tool inside a Docker container to perform the validation.
Usage: make openapi-validation
This script searches the codebase for unacceptable language patterns. It uses a predefined list of terms and searches the codebase for any matches, reporting them if found. An optional .unacceptablelanguageignore file can be added to the repository’s root, allowing certain files to be ignored during the search.
Usage: make language
This script generates a list of contributors for the repository. It uses the git shortlog command to gather commit information and formats it into a CONTRIBUTORS.txt file.
Usage: make contributors
This script installs the swift-format tool, the version can be optionally defined using the -v
parameter. If no version is specified as a parameter, the latest version will be installed.
Example to add the extra parameter in the Makefile:
install-format: curl -s $(baseUrl)/run-swift-format.sh | bash -s -- -v 510.1.0
Usage: make install-format
This script installs the Swift OpenAPI generator tool, the version can be optionally defined using the -v
parameter. If no version is specified as a parameter, the latest version will be installed.
Example to add the extra parameter in the Makefile:
install-openapi: curl -s $(baseUrl)/install-swift-openapi-generator.sh | bash -s -- -v 1.2.2
Usage: make install-openapi
This script cleans up build artifacts and other temporary files from the repository.
Usage: make run-clean
This script serves the OpenAPI documentation using an Nginx server. This try to run inside a Docker container. Optional parameters can used, these extra parameters needs to be added in the Makefile:
-n
: add a custom identifier for the container, the default isopenapi-server
-p
: add a custom port to bind it to the container, the default is8888:80
Example to add a different name:
run-openapi: curl -s $(baseUrl)/run-openapi-docker.sh | bash -s -- -n new-name
Example to add a different port:
run-openapi: curl -s $(baseUrl)/run-openapi-docker.sh | bash -s -- -p 8800:80
Usage: make run-openapi
This script checks/formats Swift code using the swift-format tool. It runs the tool on all Swift files in the repository, optionally fixing issues if the --fix argument is provided. The script attempts to read the .swift-format configuration file for format rules and ignores files listed in .swiftformatignore, if present. If any file is missing, it will download it to the repository, which can then be customized.
Usage: make lint
for run lint or make format
for run format