Skip to content

Commit 269dd90

Browse files
committed
GHA replace ktlint with integrated detekt
1 parent 93acc76 commit 269dd90

File tree

4 files changed

+186
-34
lines changed

4 files changed

+186
-34
lines changed

.github/workflows/publish_snapshot.yml

Lines changed: 88 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,97 @@ on:
77
branches: [ master ]
88

99
jobs:
10+
resolve-version:
11+
uses: ./.github/workflows/resolve-version.yml
12+
needs: [ check ]
13+
with:
14+
desired-version: ${{ github.event.release.tag_name || github.event.inputs.version }}
15+
1016
publish-snapshot:
11-
runs-on: ${{ matrix.os }}
17+
needs:
18+
- resolve-version
19+
runs-on: ${{ matrix.os.runner }}
20+
defaults:
21+
run:
22+
shell: ${{ matrix.os.shell }}
23+
env:
24+
VERSION: ${{ needs.resolve-version.outputs.version }}
25+
GH_USERNAME: ${{ github.actor }}
26+
GH_PASSWORD: ${{ github.token }}
27+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_SECRET }}
28+
ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.GPG_SIGNING_KEY_ID }}
29+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_SIGNING_PASSWORD }}
30+
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
31+
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
1232
strategy:
1333
matrix:
14-
os: [macos-latest, windows-latest, ubuntu-latest]
34+
repository:
35+
- name: Github Packages
36+
tasks: publishAllPublicationsToGitHubRepository
37+
enabled: ${{ github.event.inputs.skipGitHub != 'y' }}
38+
- name: Maven Central
39+
# `closeSonatypeStagingRepository` Requires to manually release a new version on https://s01.oss.sonatype.org/#stagingRepositories
40+
# If you're brave, you could change it to `closeAndReleaseSonatypeStagingRepository` to fully automate the release
41+
tasks: publishToSonatype closeAndReleaseSonatypeStagingRepository
42+
enabled: ${{ github.event.inputs.skipMavenCentral != 'y' }}
43+
os:
44+
- runner: macos-latest
45+
shell: bash
46+
- runner: windows-latest
47+
shell: msys2 {0}
48+
- runner: ubuntu-latest
49+
shell: bash
1550

1651
steps:
17-
- uses: actions/checkout@v2
18-
19-
- name: Publish Snapshot
20-
env:
21-
SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
22-
SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
23-
GPG_SECRET: ${{ secrets.GPG_SECRET }}
24-
GPG_SIGNING_PASSWORD: ${{ secrets.GPG_SIGNING_PASSWORD }}
25-
SNAPSHOT: 'TRUE'
26-
run: ./gradlew publish
27-
28-
- name: Archive redux-kotlin publications dir
29-
uses: actions/upload-artifact@v1
30-
with:
31-
name: publications-${{ matrix.os }}
32-
path: redux-kotlin/build/publications
33-
34-
- name: Archive redux-kotlin-threadsafe publications dir
35-
if: steps.publish.outputsexit_code == 0
36-
uses: actions/upload-artifact@v1
37-
with:
38-
name: publications-threadsafe-${{ matrix.os }}
39-
path: redux-kotlin-threadsafe/build/publications
52+
steps:
53+
- uses: msys2/setup-msys2@v2
54+
if: ${{ matrix.repository.enabled == true && runner.os == 'Windows' }}
55+
with:
56+
release: false
57+
msystem: MINGW64
58+
update: true
59+
path-type: inherit
60+
install: >-
61+
mingw-w64-x86_64-curl
62+
curl
63+
64+
- uses: actions/checkout@v3
65+
if: ${{ matrix.repository.enabled == true }}
66+
67+
- uses: actions/setup-java@v3
68+
if: ${{ matrix.repository.enabled == true }}
69+
with:
70+
distribution: 'adopt'
71+
java-version: 11
72+
73+
- name: Restore Gradle cache
74+
if: ${{ matrix.repository.enabled == true }}
75+
id: cache-gradle
76+
uses: actions/cache@v3
77+
with:
78+
path: |
79+
~/.gradle/caches
80+
~/.gradle/wrapper
81+
~/.gradle/yarn
82+
~/.gradle/nodejs
83+
~/.konan
84+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
85+
restore-keys: ${{ runner.os }}-gradle-
86+
87+
- name: Gradle Publish to ${{ matrix.repository.name }}
88+
if: ${{ matrix.repository.enabled == true }}
89+
run: ./gradlew ${{ matrix.repository.tasks }} -Pversion=${VERSION//v} --scan
90+
91+
- name: Archive redux-kotlin publications dir
92+
uses: actions/upload-artifact@v1
93+
with:
94+
name: publications-${{ matrix.os }}
95+
path: redux-kotlin/build/publications
96+
97+
- name: Archive redux-kotlin-threadsafe publications dir
98+
if: steps.publish.outputsexit_code == 0
99+
uses: actions/upload-artifact@v1
100+
with:
101+
name: publications-threadsafe-${{ matrix.os }}
102+
path: redux-kotlin-threadsafe/build/publications
40103

.github/workflows/pull_request.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,45 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v2
1515

16-
- name: Ktlint
17-
uses: "vroy/gha-kotlin-linter@v1"
16+
- uses: actions/setup-java@v3
17+
with:
18+
distribution: 'adopt'
19+
java-version: 11
20+
21+
- name: Detekt
22+
run: ./gradlew detektAll
23+
24+
- name: Make artifact location URIs relative
25+
if: ${{ always() }}
26+
continue-on-error: true
27+
run: |
28+
ls '${{ github.workspace }}/build/reports/detekt/'
29+
cp '${{ github.workspace }}/build/reports/detekt/detekt.sarif' '${{ github.workspace }}/detekt.sarif.json'
30+
echo "$(
31+
jq --arg github_workspace ${{ github.workspace }} \
32+
'. | ( .runs[].results[].locations[].physicalLocation.artifactLocation.uri |= if test($github_workspace) then .[($github_workspace | length | . + 1):] else . end )' \
33+
'${{ github.workspace }}/detekt.sarif.json'
34+
)" > '${{ github.workspace }}/detekt.sarif.json'
35+
36+
- uses: github/codeql-action/upload-sarif@v2
37+
if: ${{ always() }}
38+
with:
39+
sarif_file: ${{ github.workspace }}/detekt.sarif.json
40+
checkout_path: ${{ github.workspace }}
1841
test:
1942
needs: ktlint
2043
runs-on: ${{ matrix.os }}
2144
strategy:
2245
matrix:
23-
os: [macos-latest, windows-latest, ubuntu-latest]
46+
os: [ macos-latest, windows-latest, ubuntu-latest ]
2447
steps:
2548
- uses: actions/checkout@v2
2649

50+
- uses: actions/setup-java@v3
51+
with:
52+
distribution: 'adopt'
53+
java-version: 11
54+
2755
- name: Test
2856
run: ./gradlew allTest
2957

.github/workflows/resolve-version.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Resolve Version
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
desired-version:
7+
type: string
8+
description: Optional desired version
9+
required: false
10+
outputs:
11+
version:
12+
value: ${{ jobs.resolve.outputs.version }}
13+
snapshot:
14+
value: ${{ jobs.resolve.outputs.version }}
15+
16+
concurrency:
17+
cancel-in-progress: true
18+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
19+
20+
jobs:
21+
resolve:
22+
name: Resolve Version
23+
runs-on: ubuntu-latest
24+
env:
25+
VERSION: ${{ inputs.desired-version }}
26+
outputs:
27+
version: ${{ steps.resolve.outputs.version }}
28+
snapshot: ${{ steps.resolve.outputs.snapshot }}
29+
steps:
30+
- uses: actions/checkout@v3
31+
- name: Resolve
32+
id: resolve
33+
run: |
34+
project_version=$(cat gradle.properties | grep -Po '^version=\K(.+)')
35+
version=${VERSION:=$project_version}
36+
VERSION=${VERSION/v}
37+
echo "PROJECT_VERSION=${project_version}" >> $GITHUB_ENV
38+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
39+
echo "::set-output name=version::${VERSION}"
40+
if [[ "$VERSION" != "$project_version" ]]; then
41+
echo "DIFF_VERSION=1" >> $GITHUB_ENV
42+
fi
43+
if [[ "$VERSION" == *-SNAPSHOT ]]; then
44+
echo "::set-output name=snapshot::true"
45+
else
46+
echo "::set-output name=snapshot::false"
47+
fi
48+
- name: Report
49+
run: |
50+
echo "VERSION=${{ env.VERSION }}"
51+
echo "steps.resolve.outputs.version=${{ steps.resolve.outputs.version }}"
52+
- name: Create Snapshot
53+
if: env.DIFF_VERSION == '1'
54+
run: |
55+
main_version=$(echo $VERSION | grep -Po '^([0-9]+.){2}(?=.*)')
56+
patch_version=$(echo $VERSION | grep -Po "^$main_version\\K([0-9]+)(?=.*)")
57+
patch_version=$(expr $patch_version + 1)
58+
SNAPSHOT_VERSION="${main_version}${patch_version}-SNAPSHOT"
59+
echo "SNAPSHOT_VERSION=$SNAPSHOT_VERSION" >> $GITHUB_ENV
60+
sed -Ei "s|^(version=).*\$|\\1$SNAPSHOT_VERSION|" gradle.properties
61+
- name: Commit and push SNAPSHOT
62+
if: env.DIFF_VERSION == '1' && env.PROJECT_VERSION != env.SNAPSHOT_VERSION
63+
uses: devops-infra/action-commit-push@v0.9.2
64+
with:
65+
github_token: ${{ secrets.GH_TOKEN || github.token }}
66+
commit_message: '[ci skip] New SNAPSHOT - ${{ env.SNAPSHOT_VERSION }}'
67+
target_branch: master

build-conventions/src/main/kotlin/convention.common.gradle.kts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ idea {
3434
}
3535
}
3636

37-
tasks {
38-
withType<Test> {
39-
// useJUnitPlatform()
40-
}
41-
}
42-
4337
afterEvaluate {
4438
tasks {
4539
if (findByName("compile") == null) {

0 commit comments

Comments
 (0)