Skip to content

Commit

Permalink
test(gh-action): Added new generic actions
Browse files Browse the repository at this point in the history
Added new generic actions to use in other repositories
  • Loading branch information
gbm25 committed Dec 27, 2024
1 parent 686cacf commit 7404c42
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/code-quality-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Java Maven Code Quality

on:
workflow_call:

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '23'

formatting:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Run Spring Java Format check
run: |
if ! grep -q 'spring-javaformat-maven-plugin' pom.xml; then
echo "ERROR: Missing Spring Java Format plugin configuration in pom.xml"
echo "Refer to: https://github.com/spring-io/spring-javaformat"
exit 1
fi
mvn spring-javaformat:validate
linting:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Run Checkstyle
run: |
if ! grep -q 'maven-checkstyle-plugin' pom.xml; then
echo "ERROR: Missing Checkstyle plugin configuration in pom.xml"
echo "Refer to: https://maven.apache.org/plugins/maven-checkstyle-plugin/"
exit 1
fi
if [ ! -f "checkstyle.xml" ]; then
echo "ERROR: Missing checkstyle.xml configuration file"
echo "Refer to: https://checkstyle.sourceforge.io/"
exit 1
fi
mvn checkstyle:check
spotbugs:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Run SpotBugs
run: |
if ! grep -q 'spotbugs-maven-plugin' pom.xml; then
echo "ERROR: Missing SpotBugs plugin configuration in pom.xml"
echo "Refer to: https://github.com/spotbugs/spotbugs-maven-plugin"
exit 1
fi
mvn spotbugs:check
pmd:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Run PMD
run: |
if ! grep -q 'maven-pmd-plugin' pom.xml; then
echo "ERROR: Missing PMD plugin configuration in pom.xml"
echo "Refer to: https://maven.apache.org/plugins/maven-pmd-plugin/"
exit 1
fi
if [ ! -f "pmd.xml" ]; then
echo "ERROR: Missing pmd.xml configuration file"
echo "Refer to: https://pmd.github.io/"
exit 1
fi
mvn pmd:check
dependency-check:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Run OWASP Dependency-Check
run: |
if ! grep -q 'dependency-check-maven' pom.xml; then
echo "ERROR: Missing Dependency-Check plugin configuration in pom.xml"
echo "Refer to: https://jeremylong.github.io/DependencyCheck/dependency-check-maven/"
exit 1
fi
mvn org.owasp:dependency-check-maven:check
coverage:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Run JaCoCo tests and enforce coverage
run: |
if ! grep -q 'jacoco-maven-plugin' pom.xml; then
echo "ERROR: Missing JaCoCo plugin configuration in pom.xml"
echo "Refer to: https://www.eclemma.org/jacoco/trunk/doc/maven.html"
exit 1
fi
mvn test jacoco:report jacoco:check
75 changes: 75 additions & 0 deletions .github/workflows/config/changelog-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"categories": [
{
"title": "## 🚀 Features",
"labels": ["feature", "enhancement"]
},
{
"title": "## 🐛 Fixes",
"labels": ["fix", "bug"]
},
{
"title": "## 📚 Documentation",
"labels": ["docs", "documentation"]
},
{
"title": "## 🧪 Tests",
"labels": ["test", "testing"]
},
{
"title": "## 🛠️ Maintenance",
"labels": ["chore", "refactor", "ci"]
}
],
"ignore_labels": [
"wip", "ignore", "do-not-merge"
],
"sort": {
"order": "DESC",
"on_property": "mergedAt"
},
"template": "# Changelog for Release\n\n#{{CHANGELOG}}\n\n<details>\n<summary>Uncategorized Changes</summary>\n\n#{{UNCATEGORIZED}}\n</details>",
"pr_template": "- {{TITLE}} ([#{{NUMBER}}](https://github.com/{{REPO}}/pull/{{NUMBER}})) by @{{AUTHOR}}",
"empty_template": "No changes in this release.",
"label_extractor": [
{
"pattern": "^\\[(feature|fix|docs|test|chore|ci|enhancement|bug|refactor|dependencies|documentation|testing)\\]",
"target": "$1",
"flags": "i"
},
{
"pattern": "(feature|fix|docs|test|chore|ci|enhancement|bug|refactor|dependencies|documentation|testing)",
"on_property": "title",
"method": "match",
"flags": "i"
}
],
"duplicate_filter": {
"pattern": "^(\\[Issue\\]|\\[Task\\]).*",
"on_property": "title",
"method": "match"
},
"transformers": [
{
"pattern": "(- \\[.+\\]\\()(.+?)(\\))",
"target": "- [$2]$3"
}
],
"trim_values": true,
"max_tags_to_fetch": 100,
"max_pull_requests": 100,
"max_back_track_time_days": 180,
"exclude_merge_branches": [
"feature/experimental", "hotfix"
],
"base_branches": [
"main", "develop"
],
"tag_resolver": {
"method": "semver",
"filter": {
"pattern": "v(\\d+\\.\\d+\\.\\d+)",
"flags": "gu"
}
}
}
39 changes: 39 additions & 0 deletions .github/workflows/detect-language.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Detect Main Language

on:
workflow_call:

jobs:
detect-language:
runs-on: ubuntu-latest
outputs:
language: ${{ steps.language.outputs.language }}
steps:
- name: Install jq
run: sudo apt-get install jq

- name: Get main language of repository
id: language
run: |
# Fetch the main language and set it as output directly
echo "language=$(curl -s https://api.github.com/repos/${{ github.repository }} | jq -r .language)" >> $GITHUB_OUTPUT
- name: Supported language of workflows
run: |
SUPPORTED_LANGUAGES=("Java" "Python" "Rust" "Go" "Dart" "JavaScript" "C++")
LANGUAGE_SUPPORTED=false
# Loop to check if the detected language is supported
for SUPPORTED_LANGUAGE in "${SUPPORTED_LANGUAGES[@]}"; do
if [[ "$SUPPORTED_LANGUAGE" == "${{ steps.language.outputs.language }}" ]]; then
LANGUAGE_SUPPORTED=true
break
fi
done
if $LANGUAGE_SUPPORTED; then
echo "Supported language detected: ${{ steps.language.outputs.language }}"
else
echo "Error: The detected language (${{ steps.language.outputs.language }}) is not supported in subsequent workflows that rely on this one."
exit 1
fi
41 changes: 41 additions & 0 deletions .github/workflows/pr-changelog-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: PR Changelog Preview

on:
workflow_dispatch:

permissions:
pull-requests: write

jobs:
changelog_preview:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Get GH Zero Day Code APP token
if: ${{ !github.event.act }}
uses: actions/create-github-app-token@v1
id: zdc-auth-app-token
with:
app-id: ${{ vars.ZDC_AUTH_APP_ID }}
private-key: ${{ secrets.ZDC_AUTH_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: Generate Changelog Preview
id: changelog
uses: mikepenz/release-changelog-builder-action@v5
with:
configuration: config/changelog-config.json
env:
GITHUB_TOKEN: ${{ steps.zdc-auth-app-token.outputs.token }}

- name: Post Changelog to PR
uses: marocchino/sticky-pull-request-comment@v2
with:
header: changelog-preview
message: |
## Changelog Preview
${{ steps.changelog.outputs.changelog }}
env:
GITHUB_TOKEN: ${{ steps.zdc-auth-app-token.outputs.token }}
42 changes: 42 additions & 0 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release workflow
on:
workflow_call:

jobs:
update-changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Get GH Zero Day Code APP token
if: ${{ !github.event.act }}
uses: actions/create-github-app-token@v1
id: zdc-auth-app-token
with:
app-id: ${{ vars.ZDC_AUTH_APP_ID }}
private-key: ${{ secrets.ZDC_AUTH_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: Generate Changelog
id: changelog
uses: mikepenz/release-changelog-builder-action@v5
with:
configuration: config/changelog-config.json
env:
GITHUB_TOKEN: ${{ steps.zdc-auth-app-token.outputs.token }}

- name: Append Changelog to CHANGELOG.md
uses: andstor/[email protected]
with:
path: CHANGELOG.md
content: ${{ steps.changelog.outputs.changelog }}
write-mode: append

- name: Commit and Push Changes
uses: EndBug/[email protected]
with:
message: 'Update CHANGELOG.md with latest changes'
add: 'CHANGELOG.md'
env:
GITHUB_TOKEN: ${{ steps.zdc-auth-app-token.outputs.token }}
28 changes: 28 additions & 0 deletions .github/workflows/unified-code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Unifies Code Quality

on:
workflow_call:

jobs:
detect-and-trigger:
runs-on: ubuntu-latest

steps:
- name: Call Detect Main Language workflow
id: detect_language
uses: ${{ github.repository_owner }}/app-summoner-sync/.github/workflows/detect-language.yml@feature/new-github-actions

- name: Check if the detected language is Java
id: check_java
run: |
if [[ "${{ steps.detect_language.outputs.language }}" == "Java" ]]; then
echo "Java detected, triggering Java Maven Code Quality workflow"
echo "trigger_java=true" >> $GITHUB_ENV
else
echo "Language detected is not Java. Skipping Java Maven Code Quality."
echo "trigger_java=false" >> $GITHUB_ENV
trigger-java-code-quality:
if: ${{ env.trigger_java == 'true' }}
needs: detect-and-trigger
uses: ${{ github.repository_owner }}/app-summoner-sync/.github/workflows/java-maven-code-quality.yml@feature/new-github-actions

0 comments on commit 7404c42

Please sign in to comment.