vector-im/element-x-ios/issues/14 - Initial Danger setup

This commit is contained in:
Stefan Ceriu 2022-04-26 17:21:32 +03:00
parent 0a0f41689a
commit 1b1b541a63
6 changed files with 103 additions and 6 deletions

20
.github/workflows/danger.yml vendored Normal file
View File

@ -0,0 +1,20 @@
name: Danger CI
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
name: Danger
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.danger-swift
key: danger-swift-cache-key
- name: Danger
uses: docker://ghcr.io/danger/danger-swift-with-swiftlint:3.12.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -46,6 +46,3 @@ custom_rules:
match_kinds: identifier
message: "MXLog should be used instead of os_log()"
severity: error

View File

@ -103,10 +103,10 @@
"system": {
"macos": {
"monterey": {
"HOMEBREW_VERSION": "3.4.8",
"HOMEBREW_VERSION": "3.4.9",
"HOMEBREW_PREFIX": "/opt/homebrew",
"Homebrew/homebrew-core": "c8e031fcd136549b38e0275bc7a3f9969caa60d3",
"CLT": "12.5.0.22.9",
"Homebrew/homebrew-core": "297be05c529835e0e211de450aa55836b6b1fca7",
"CLT": "13.0.0.0.1.1627064638",
"Xcode": "13.3.1",
"macOS": "12.2.1"
}

77
Dangerfile.swift Normal file
View File

@ -0,0 +1,77 @@
import Foundation
import Danger
SwiftLint.lint(inline: true)
let danger = Danger()
// Warn when there is a big PR
if (danger.github.pullRequest.additions ?? 0) > 500 {
warn("This pull request seems relatively large. Please consider splitting it into multiple smaller ones.")
}
// Check that the PR has a description
if danger.github.pullRequest.body?.isEmpty ?? true {
warn("Please provide a description for this PR.")
}
// Request a changelog for each app change
let editedFiles = danger.git.modifiedFiles + danger.git.createdFiles
let hasChangelog = danger.git.modifiedFiles.contains("/changelog.d")
if editedFiles.count > 0 && !hasChangelog {
warn("Please add a changelog.")
}
// Check for a ticket number
if let ticketNumberRegex = try? NSRegularExpression(pattern: "#\\d+") {
let missingTicketNumber = !danger.git.commits.filter {
!$0.message.contains("vector-im/element-x-ios/issues/") &&
ticketNumberRegex.firstMatch(in: $0.message, options: [], range: .init(location: 0, length: $0.message.utf16.count)) == nil
}.isEmpty
if missingTicketNumber {
warn("Some of the commits are missing ticket numbers. Please consinder using them for better tracking.")
}
}
// Check for a sign-off
let signOff = "Signed-off-by:"
let allowList = ["stefanceriu",
"Johennes",
"yostyle",
"SBiOSoftWhare",
"ismailgulek",
"Anderas",
"pixlwave",
"langleyd",
"manuroe",
"gileluard",
"phlniji",
"MaximeEvrard42",
"aringenbach"]
let requiresSignOff = !allowList.contains(where: {
$0.caseInsensitiveCompare(danger.github.pullRequest.user.login) == .orderedSame
})
if requiresSignOff {
let hasPRBodySignOff = danger.github.pullRequest.body?.contains(signOff) ?? false
let isMissingCommitsSignOff = !danger.git.commits.filter {
!$0.message.contains(signOff)
}.isEmpty
if !hasPRBodySignOff && isMissingCommitsSignOff {
fail("Please add a sign-off to either the PR description or to the commits themselves.")
}
}
// Check for screenshots on view changes
let hasChangedViews = !editedFiles.filter { $0.lowercased().contains("/view") }.isEmpty
if hasChangedViews {
if (danger.github.pullRequest.body?.contains("user-images") ?? false) == false {
warn("You seem to have made changes to views. Please consider adding screenshots.")
}
}

View File

@ -1623,6 +1623,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
@ -1687,6 +1688,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;

View File

@ -10,6 +10,7 @@ options:
createIntermediateGroups: true
deploymentTarget:
iOS: "15.0"
macOS: "12.0"
settings:
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED: YES