Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add format, lint, Makefile, and publish from CI #6

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@ name: CI
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
lfs: true

- run: make lint-ci
- run: make format-ci

build:
runs-on: macos-14
permissions:
# https://docs.npmjs.com/generating-provenance-statements#publishing-packages-with-provenance-via-github-actions
id-token: write
steps:
- uses: actions/[email protected]
with:
Expand All @@ -26,6 +41,9 @@ jobs:
key: v0-${{ runner.os }}-swiftpm-${{ hashFiles('**/Package.resolved') }}
restore-keys: v0-${{ runner.os }}-swiftpm-

- run: npm run build
- run: npm publish --provenance --access public --dry-run

- run: file build/Release/PreviewExtension.appex/Contents/MacOS/*
- run: npm publish --provenance --access public
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
3 changes: 3 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--swiftversion 5.2
--indent 2
--maxwidth 120
15 changes: 15 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
strict: true

excluded:
- .build
- .swiftpm-packages

disabled_rules:
- function_body_length
- type_body_length
- file_length
- cyclomatic_complexity
- opening_brace # handled by swiftformat

trailing_comma:
mandatory_comma: true
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.PHONY: build
build:
# https://developer.apple.com/documentation/xcode/building-swift-packages-or-apps-that-use-them-in-continuous-integration-workflows
# https://stackoverflow.com/questions/4969932/separate-build-directory-using-xcodebuild
xcodebuild \
-disableAutomaticPackageResolution \
-clonedSourcePackagesDirPath .swiftpm-packages \
-destination generic/platform=macOS \
-scheme PreviewExtension \
SYMROOT=$(PWD)/build \
-configuration Release \
clean build
lipo build/Release/PreviewExtension.appex/Contents/MacOS/PreviewExtension -verify_arch arm64 x86_64
rm -rf dist
mkdir -p dist
cp -R build/Release/PreviewExtension.appex dist/
cp PreviewExtension/PreviewExtension.entitlements dist/

.PHONY: lint-ci
lint-ci:
docker run -t --rm -v $(PWD):/work -w /work ghcr.io/realm/swiftlint:0.53.0

.PHONY: format-ci
format-ci:
docker run -t --rm -v $(PWD):/work ghcr.io/nicklockwood/swiftformat:0.53.7 --lint /work
6 changes: 4 additions & 2 deletions PreviewExtension/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ struct Configuration {

extension Configuration {
static func fromMainBundle() throws -> Configuration {
guard let dict = (Bundle.main.localizedInfoDictionary ?? Bundle.main.infoDictionary)?["QLJS"] as? [String: Any] else {
guard let dict = (Bundle.main.localizedInfoDictionary ?? Bundle.main.infoDictionary)?["QLJS"] as? [String: Any]
else {
throw GenericError(message: "Could not read QLJS configuration from Info.plist")
}

Expand Down Expand Up @@ -46,6 +47,7 @@ extension Configuration {
return Configuration(
loadingStrategy: loadingStrategy,
pageURL: pageURL,
preferredContentSize: preferredContentSize)
preferredContentSize: preferredContentSize
)
}
}
Loading