Skip to content

Commit

Permalink
Reconfigure GitHub Actions & downgrade Swift
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Aug 15, 2021
1 parent 52d6a06 commit 56d33bd
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 75 deletions.
25 changes: 1 addition & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,10 @@
name: CI
name: Main

on:
push:
branches: [main, versions]
pull_request:
branches: [main]

jobs:
cancel-previous-runs:
runs-on: ubuntu-latest

steps:
- name: Cancel previous runs of this workflow on same branch
uses: rokroskar/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

anylint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Install AnyLint
run: brew tap Flinesoft/AnyLint https://github.com/Flinesoft/AnyLint.git && brew install anylint

- name: Run AnyLint
run: anylint

test-linux:
runs-on: ubuntu-latest

Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Pull Request

on:
pull_request:
branches: [main]

jobs:
cancel-previous-runs:
runs-on: ubuntu-latest

steps:
- name: Cancel previous runs of this workflow on same branch
uses: rokroskar/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

anylint:
runs-on: macos-latest

steps:
- uses: actions/checkout@v2

- name: Install AnyLint
run: brew tap Flinesoft/AnyLint https://github.com/Flinesoft/AnyLint.git && brew install anylint

- name: Run AnyLint
run: anylint

test-linux:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Run tests
run: swift test -v --enable-test-discovery

test-macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v2

- name: Run tests
run: swift test -v --enable-code-coverage
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se

## [Unreleased]
### Added
- YAML-based configuration file. Supportts `FilePaths` and `FileContents` as well as `CustomScripts` for full feature parity with previous Swift-based configuration file.
- YAML-based configuration file. Supports `FilePaths` and `FileContents` as well as `CustomScripts` for full feature parity with previous Swift-based configuration file.
Author: [Cihat Gündüz](https://github.com/Jeehut)
### Changed
- Migrated from jakeheis/SwiftCLI to apple/swift-argument-parser for improved reliability & reduced maintenance.
Expand All @@ -31,7 +31,7 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se
### Removed
- Swift-based configuration file support removed in favor of YAML-based configuration. All features supported via the Swift file still supported via YAML file. See README.md for more details. Parameters were not renamed to keep migration simple.
Author: [Cihat Gündüz](https://github.com/Jeehut)
- Support for Swift versions below 5.5 was dropped to make use of the latest improvements in concurrency & SwiftPM plugin system. Use version `0.8.2` if you need to stay on lower Swift versions.
- Support for Swift versions below 5.4 was dropped to make use of the latest improvements in Swift & SwiftPM. Use version `0.8.2` if you need to stay on lower Swift versions.
Author: [Cihat Gündüz](https://github.com/Jeehut)
### Fixed
- Issues with paths due to Swift scripting not being as easy to use now fixed by moving over to YAML-based configuration. For custom scripts, responsibility is moved to the user side by allowing to specify the exact command to run.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Flinesoft (alias Cihat Gündüz)
Copyright (c) 2020-2021 Flinesoft (alias Cihat Gündüz)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5
// swift-tools-version:5.3
import PackageDescription

let package = Package(
Expand Down Expand Up @@ -44,7 +44,7 @@ let package = Package(
.product(name: "OrderedCollections", package: "swift-collections"),
]
),
.executableTarget(
.target(
name: "Commands",
dependencies: [
"Checkers",
Expand Down
1 change: 1 addition & 0 deletions Sources/Checkers/Helpers/FilesSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final class FilesSearch {
excludeFilters: excludeFilters
)

// AnyLint.skipHere: IfAsGuard
if let cachedFilePaths: [String] = cachedFilePaths[searchOptions] {
return cachedFilePaths
}
Expand Down
1 change: 0 additions & 1 deletion Sources/Commands/AnyLint.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation
import ArgumentParser

@main
/// The entry point of the toot, defines the `anylint` primary command. Sets up any sub commands like `init` or `lint`.
struct AnyLint: ParsableCommand {
static var configuration: CommandConfiguration = .init(
Expand Down
5 changes: 5 additions & 0 deletions Sources/Commands/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ArgumentParser

// TODO: [cg_2021-08-15] remove in favor of `@main` in AnyLint struct once GitHub has macos-11 available:
// https://github.com/actions/virtual-environments/issues/2486
AnyLint.main()
1 change: 0 additions & 1 deletion Sources/Core/Severity.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import AppKit

/// Defines the severity of a lint check.
public enum Severity: String, CaseIterable, Codable {
Expand Down
45 changes: 1 addition & 44 deletions lint.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/local/bin/swift-sh
import AnyLint // .
import AnyLint // @Flinesoft
import Utility
import ShellOut // @JohnSundell

Expand Down Expand Up @@ -440,49 +440,6 @@ try Lint.logSummaryAndExit(arguments: CommandLine.arguments) {
]
)

// MARK: LinuxMainUpToDate
try Lint.customCheck(checkInfo: "LinuxMainUpToDate: The tests in Tests/LinuxMain.swift should be up-to-date.") { checkInfo in
var violations: [Violation] = []

let linuxMainFilePath = "Tests/LinuxMain.swift"
let linuxMainContentsBeforeRegeneration = try! String(contentsOfFile: linuxMainFilePath)

let sourceryDirPath = ".sourcery"
let testsDirPath = "Tests/\(projectName)Tests"
let stencilFilePath = "\(sourceryDirPath)/LinuxMain.stencil"
let generatedLinuxMainFilePath = "\(sourceryDirPath)/LinuxMain.generated.swift"

let sourceryInstallPath = try? shellOut(to: "which", arguments: ["sourcery"])
guard sourceryInstallPath != nil else {
log.message(
"Skipped custom check \(checkInfo) – requires Sourcery to be installed, download from: https://github.com/krzysztofzablocki/Sourcery",
level: .warning
)
return []
}

try! shellOut(to: "sourcery", arguments: ["--sources", testsDirPath, "--templates", stencilFilePath, "--output", sourceryDirPath])
let linuxMainContentsAfterRegeneration = try! String(contentsOfFile: generatedLinuxMainFilePath)

// move generated file to LinuxMain path to update its contents
try! shellOut(to: "mv", arguments: [generatedLinuxMainFilePath, linuxMainFilePath])

if linuxMainContentsBeforeRegeneration != linuxMainContentsAfterRegeneration {
violations.append(
Violation(
checkInfo: checkInfo,
filePath: linuxMainFilePath,
appliedAutoCorrection: AutoCorrection(
before: linuxMainContentsBeforeRegeneration,
after: linuxMainContentsAfterRegeneration
)
)
)
}

return violations
}

// MARK: Logger
try Lint.checkFileContents(
checkInfo: "Logger: Don't use `print` – use `log.message` instead.",
Expand Down

0 comments on commit 56d33bd

Please sign in to comment.