From b085fc982dce90177021d235f158fb71491e99da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Mendelski?= Date: Mon, 30 Sep 2024 00:46:36 +0200 Subject: [PATCH] Update github actions --- .github/workflows/build.yml | 113 +++++++++++-- .../{pull-request.yml => dependabot.yml} | 4 +- .github/workflows/release.yml | 160 +++++------------- .github/workflows/stale.yml | 27 --- build.gradle.kts | 7 +- 5 files changed, 143 insertions(+), 168 deletions(-) rename .github/workflows/{pull-request.yml => dependabot.yml} (93%) delete mode 100644 .github/workflows/stale.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3491d9d..a3ccc0e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,35 +1,114 @@ name: Build -on: [pull_request, push, workflow_dispatch] +on: + pull_request: + workflow_dispatch: + push: + tags: + - 'v*' + branches-ignore: + - 'dependabot/**' + - 'gh-pages' jobs: build: runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" + timeout-minutes: 15 + if: | + (github.event_name != 'pull_request' && !github.event.pull_request.head.repo.fork) + || (github.event_name == 'pull_request' && (github.event.pull_request.head.repo.fork || startsWith(github.head_ref, 'dependabot/'))) steps: - name: Checkout - uses: actions/checkout@v3 - - - name: Skip duplicates and docs - id: skip - uses: fkirc/skip-duplicate-actions@v5 - with: - paths_ignore: '["**/README.md", "LICENSE", ".gitignore", ".editorconfig", ".idea/**"]' + uses: actions/checkout@v4 - name: Validate gradle wrapper - if: steps.skip.outputs.should_skip != 'true' - uses: gradle/wrapper-validation-action@v1 + uses: gradle/actions/wrapper-validation@v3 + + - name: Setup Gradle + uses: gradle/gradle-build-action@v3 - name: Setup JDK - if: steps.skip.outputs.should_skip != 'true' - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 cache: gradle distribution: temurin - - name: Build with gradle - if: steps.skip.outputs.should_skip != 'true' - env: - COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} + - name: Build run: ./gradlew build + + - name: Publish Test Report + if: success() || failure() # run this step even if previous step failed + continue-on-error: true + uses: dorny/test-reporter@v1 + with: + name: test report + path: ./**/build/test-results/test/*.xml + reporter: java-junit + + - name: Publish Coverage Report + uses: codecov/codecov-action@v4 + if: | + github.repository == 'coditory/gradle-integration-test-plugin' + && github.ref == 'refs/heads/master' + with: + token: ${{ secrets.CODECOV_TOKEN }} + override_commit: ${{ github.event.workflow_run.head_sha }} + override_branch: ${{ github.event.workflow_run.head_branch }} + override_build: ${{ github.event.workflow_run.id }} + disable_search: true + files: build/reports/jacoco/coverage/coverage.xml + + - name: Import GPG Key + id: gpg + uses: crazy-max/ghaction-import-gpg@v6 + if: | + github.repository == 'coditory/gradle-integration-test-plugin' + && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + git_user_signingkey: true + git_commit_gpgsign: true + git_committer_name: Coditory Bot + git_committer_email: bot@coditory.com + + - name: Publish Release + id: publish-release + if: | + github.repository == 'coditory/gradle-integration-test-plugin' + && startsWith(github.ref, 'refs/tags/v') + && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') + env: + GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} + GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} + NEXT_VERSION: ${{ steps.versions.outputs.next_version }} + run: | + ./gradlew publishPlugins \ + -Pgradle.publish.key=$GRADLE_PUBLISH_KEY \ + -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET \ + -Pversion=$NEXT_VERSION + + - name: Generate Release Notes + id: generate-release-notes + if: steps.publish-release.conclusion == 'success' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + declare -r NOTES="$(gh api \ + --method POST \ + -H "Accept: application/vnd.github+json" \ + /repos/${{ github.repository }}/releases/generate-notes \ + -f target_commitish='master' \ + -f tag_name=${GITHUB_REF_NAME:1} \ + | jq -r '.body')" + declare -r ESCAPED="${NOTES//$'\n'/'%0A'}" + echo "notes=$ESCAPED" >> $GITHUB_OUTPUT + + - name: Create github release + if: steps.generate-release-notes.conclusion == 'success' + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + body: ${{ steps.notes.outputs.notes }} + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/dependabot.yml similarity index 93% rename from .github/workflows/pull-request.yml rename to .github/workflows/dependabot.yml index 148c4fb..3b20809 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/dependabot.yml @@ -9,7 +9,7 @@ jobs: contents: read pull-requests: write steps: - - uses: actions/labeler@v4 + - uses: actions/labeler@v5 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" @@ -22,7 +22,7 @@ jobs: steps: - name: Dependabot metadata id: dependabot-metadata - uses: dependabot/fetch-metadata@v2.2.0 + uses: dependabot/fetch-metadata@v2 - name: Enable auto-merge for Dependabot PRs run: gh pr merge --auto --rebase "$PR_URL" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a86adfa..80eeb22 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,44 +3,29 @@ name: Release on: workflow_dispatch: inputs: + section: + type: choice + description: Create release tag by incrementing sem-ver section. + options: + - PATCH + - MINOR + - MAJOR + - RERUN + - MANUAL + required: true + default: PATCH version: type: string description: | - Release version in semantic format (like: 1.2.3). - No value means a new patch version. + Manually setup version (like: 1.2.3). required: false - publish: - type: choice - description: | - Artifact publication. - Use for creating draft release notes. - options: - - SKIP - - RELEASE - required: true - default: RELEASE - release: - types: [published] jobs: release: runs-on: ubuntu-latest steps: - - name: Validate build succeeded - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - declare -r BUILD_SUCCESS="$(gh api \ - -H "Accept: application/vnd.github+json" \ - /repos/${{ github.repository }}/actions/runs?status=success\&head_sha=${{ github.sha }} \ - | jq 'limit(1; .workflow_runs[] | select(.name == "Build" and .conclusion == "success"))')" - if [ -z "$BUILD_SUCCESS" ]; then - echo "Commit did not pass Build!" - exit 1 - fi - - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.CI_TOKEN }} @@ -48,104 +33,43 @@ jobs: - name: Get versions id: versions env: - NEXT_INPUT_VERSION: ${{ inputs.version }} - TAG_NAME: ${{ github.event.release.tag_name }} + MANUAL_VERSION: ${{ inputs.version }} + INCREMENT_SECTION: ${{ inputs.section }} run: | - declare -r GIT_VERSION="$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' | sort -V | tail -n 1 | cut -c2-)" + declare -r GIT_VERSION="$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | head -n 1 | cut -c2-)" declare -r VERSION=${GIT_VERSION:-0.0.0} declare -r MAJOR="$(echo "$VERSION" | cut -d. -f1)" declare -r MINOR="$(echo "$VERSION" | cut -d. -f2)" declare -r PATCH="$(echo "$VERSION" | cut -d. -f3)" - declare -r NEXT_TAG_VERSION="$([[ "$TAG_NAME" =~ v.* ]] \ - && (echo "$TAG_NAME" | cut -c2-) \ - || echo "$TAG_NAME")" - declare -r NEXT_MANUAL_VERSION="${NEXT_INPUT_VERSION:-$NEXT_TAG_VERSION}" - declare -r NEXT_PATCH_VERSION="$MAJOR.$MINOR.$(( $PATCH + 1 ))" - declare -r NEXT_VERSION="${NEXT_MANUAL_VERSION:-$NEXT_PATCH_VERSION}" - echo ::set-output name=version::$VERSION - echo ::set-output name=next_version::$NEXT_VERSION - echo -e "VERSION: $VERSION\nNEXT_VERSION: $NEXT_VERSION" - - - name: Import GPG key - id: gpg - uses: crazy-max/ghaction-import-gpg@v5 - if: | - github.event_name != 'release' - && github.ref == 'refs/heads/master' - with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.GPG_PASSPHRASE }} - git_user_signingkey: true - git_commit_gpgsign: true - git_committer_name: Coditory Bot - git_committer_email: bot@coditory.com - - - name: Update version in README (master only) - if: steps.gpg.conclusion == 'success' - env: - PREV_VERSION: ${{ steps.versions.outputs.version }} - NEXT_VERSION: ${{ steps.versions.outputs.next_version }} - run: | - declare -r ESC_PREV_VERSION="${PREV_VERSION//./\\.}" - echo "Changing: $PREV_VERSION -> $NEXT_VERSION" - sed -i "s|${ESC_PREV_VERSION}|${NEXT_VERSION}|" README.md - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -a -m "Update version $PREV_VERSION -> $NEXT_VERSION" -m "[ci skip]" - git push origin master + declare NEXT_VERSION="" + if [ "$INCREMENT_SECTION" == "MANUAL" ]; then + if [ "$MANUAL_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]; then + NEXT_VERSION="$MANUAL_VERSION" + else + echo "Invalid manual version: $MANUAL_VERSION" >&2 + return 1 + fi + elif [ "$INCREMENT_SECTION" == "PATCH" ]; then + NEXT_VERSION="$MAJOR.$MINOR.$(( PATCH + 1 ))" + elif [ "$INCREMENT_SECTION" == "MINOR" ]; then + NEXT_VERSION="$MAJOR.$(( MINOR + 1 )).0" + elif [ "$INCREMENT_SECTION" == "MAJOR" ]; then + NEXT_VERSION="$(( MAJOR + 1 )).0.0" + elif [ "$INCREMENT_SECTION" == "RERUN" ]; then + NEXT_VERSION="$VERSION" + git tag -d "v$NEXT_VERSION" || echo "Local tag does not exist: v$NEXT_VERSION" + git push --delete origin "v$NEXT_VERSION" || echo "Remote tag does not exist: v$NEXT_VERSION" else - echo "Nothing changed. Skipping commit." + echo "Unrecognized option: $INCREMENT_SECTION" >&2 + return 1 fi + echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo -e "VERSION: $VERSION\nNEXT_VERSION: $NEXT_VERSION" - - name: Setup JDK - if: inputs.publish != 'SKIP' - uses: actions/setup-java@v3 - with: - java-version: 17 - cache: gradle - distribution: temurin - - - name: Publish to Gradle Plugin Portal - if: | - github.event_name == 'release' - || inputs.publish == 'RELEASE' - env: - GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} - GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} - NEXT_VERSION: ${{ steps.versions.outputs.next_version }} - run: | - ./gradlew publishPlugins \ - -Pgradle.publish.key=$GRADLE_PUBLISH_KEY \ - -Pgradle.publish.secret=$GRADLE_PUBLISH_SECRET \ - -Pversion=$NEXT_VERSION - - - name: Generate release notes - id: notes - if: | - github.event_name != 'release' - && github.ref == 'refs/heads/master' + - name: Create Release Tag env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PREV_VERSION: ${{ steps.versions.outputs.version }} NEXT_VERSION: ${{ steps.versions.outputs.next_version }} run: | - declare -r NOTES="$(gh api \ - --method POST \ - -H "Accept: application/vnd.github+json" \ - /repos/${{ github.repository }}/releases/generate-notes \ - -f tag_name="v$NEXT_VERSION" \ - -f target_commitish='master' \ - -f previous_tag_name="v$PREV_VERSION" \ - | jq -r '.body')" - declare -r ESCAPED="${NOTES//$'\n'/'%0A'}" - echo ::set-output name=notes::$ESCAPED - - - name: Create github release (master only) - if: steps.notes.conclusion == 'success' - uses: ncipollo/release-action@v1 - with: - allowUpdates: true - body: ${{ steps.notes.outputs.notes }} - draft: ${{ inputs.publish == 'SKIP' }} - tag: v${{ steps.versions.outputs.next_version }} - token: ${{ secrets.GITHUB_TOKEN }} + git tag "v$NEXT_VERSION" + git push origin "v$NEXT_VERSION" diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index 80d3d6f..0000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: 'Stale issues and PRs' -on: - schedule: - - cron: '30 1 * * *' - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v7 - with: - # PRs - stale-pr-message: 'This PR is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 10 days.' - days-before-pr-stale: 120 - close-pr-message: 'This PR was closed because it has been stalled for 10 days with no activity.' - days-before-pr-close: 10 - exempt-all-pr-assignees: true - exempt-pr-labels: 'awaiting-approval,work-in-progress' - stale-pr-label: 'stale' - # Issues - stale-issue-message: 'This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 5 days.' - days-before-issue-stale: 60 - close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.' - days-before-issue-close: 5 - exempt-issue-assignees: true - exempt-issue-labels: 'awaiting-approval,work-in-progress' - stale-issue-label: 'stale' diff --git a/build.gradle.kts b/build.gradle.kts index ffee752..4ed5597 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,9 @@ plugins { kotlin("jvm") version "2.0.20" id("jacoco") - id("com.github.kt3k.coveralls") version "2.12.2" - id("com.gradle.plugin-publish") version "1.3.0" id("java-gradle-plugin") id("maven-publish") + id("com.gradle.plugin-publish") version "1.3.0" id("org.jlleitschuh.gradle.ktlint") version "12.1.1" } @@ -53,8 +52,8 @@ tasks.jacocoTestReport { } } -coveralls { - sourceDirs = listOf("src/main/kotlin") +tasks.test { + finalizedBy(tasks.jacocoTestReport) } // Marking new version (incrementPatch [default], incrementMinor, incrementMajor)