From 5852d0a41f3fcd1a2f3e92487df3a06c35643b6e Mon Sep 17 00:00:00 2001 From: Noor Dawod Date: Wed, 8 May 2024 12:41:45 +0200 Subject: [PATCH] Introduce a workflow for linting and building. --- .github/actions/clone/action.yml | 14 ++++++++++++++ .github/actions/lint/action.yml | 11 +++++++++++ .github/workflows/build.yml | 21 +++++++++++++++++++++ .github/workflows/publish.yml | 31 ++++++------------------------- 4 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 .github/actions/clone/action.yml create mode 100644 .github/actions/lint/action.yml create mode 100644 .github/workflows/build.yml diff --git a/.github/actions/clone/action.yml b/.github/actions/clone/action.yml new file mode 100644 index 0000000..f9af81c --- /dev/null +++ b/.github/actions/clone/action.yml @@ -0,0 +1,14 @@ +name: "Clone code and set up Java" + +runs: + using: "composite" + steps: + - name: "Clone code" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: "Set up Adopt OpenJDK 17" + uses: actions/setup-java@v3 + with: + distribution: adopt + java-version: 17 diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml new file mode 100644 index 0000000..03b7a6c --- /dev/null +++ b/.github/actions/lint/action.yml @@ -0,0 +1,11 @@ +name: "Lint code" + +runs: + using: "composite" + steps: + - name: "Clone code and set up Java" + uses: ./.github/actions/clone + - name: "Detekt" + run: sh gradlew detekt + - name: "KtLint" + run: sh gradlew ktlintCheck diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..923f8ed --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,21 @@ +name: "Lint and build code" + +on: + push: + branches: + - "**" + - "!main" + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: "Lint code" + uses: ./.github/actions/lint + + build: + needs: lint + runs-on: macos-latest + steps: + - name: "Validate Gradle wrapper" + uses: gradle/wrapper-validation-action@v1 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 932bf60..7db65d6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,41 +1,22 @@ -name: Publish +name: "Lint and build code, and publish artifacts to repository" + on: push: branches: - - main + - "main" jobs: lint: runs-on: ubuntu-latest steps: - - name: "Clone repo" - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: "Set up Adopt OpenJDK 17" - uses: actions/setup-java@v3 - with: - distribution: adopt - java-version: 17 - - name: "Detekt" - run: sh gradlew detekt - - name: "KtLint" - run: sh gradlew ktlintCheck + - name: "Lint code" + uses: ./.github/actions/lint build: needs: lint runs-on: macos-latest steps: - - name: "Clone repo" - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: "Set up Adopt OpenJDK 17" - uses: actions/setup-java@v3 - with: - distribution: adopt - java-version: 17 - - name: Validate Gradle wrapper + - name: "Validate Gradle wrapper" uses: gradle/wrapper-validation-action@v1 publish: