Skip to content

Commit

Permalink
Update github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
pmendelski committed Sep 30, 2024
1 parent 267ccc4 commit b085fc9
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 168 deletions.
113 changes: 96 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"

Expand All @@ -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"
Expand Down
160 changes: 42 additions & 118 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,149 +3,73 @@ 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 }}

- 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"
27 changes: 0 additions & 27 deletions .github/workflows/stale.yml

This file was deleted.

7 changes: 3 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
}

Expand Down Expand Up @@ -53,8 +52,8 @@ tasks.jacocoTestReport {
}
}

coveralls {
sourceDirs = listOf("src/main/kotlin")
tasks.test {
finalizedBy(tasks.jacocoTestReport)
}

// Marking new version (incrementPatch [default], incrementMinor, incrementMajor)
Expand Down

0 comments on commit b085fc9

Please sign in to comment.