diff --git a/.github/workflows/.reusable-common-pr-check.yaml b/.github/workflows/.common-pr-check.yml similarity index 67% rename from .github/workflows/.reusable-common-pr-check.yaml rename to .github/workflows/.common-pr-check.yml index 7eb6a80..8c4fbe2 100644 --- a/.github/workflows/.reusable-common-pr-check.yaml +++ b/.github/workflows/.common-pr-check.yml @@ -43,28 +43,13 @@ jobs: break; } } - + let commentBody = `Please update your pull request title to the required format: - + **RegEx** \`\`\` ${{ vars.PR_POLICY_TITLE_PATTERN }} \`\`\` - - **Simplified** - \`\`\` - \[\!\]: - \`\`\` - - * \`type\` - The type of pull request. This can be one of the following types: - * \`feat\` - An implementation of a feature; increments the Minor version unless suffixed with \`\!\`. - * \`fix\` - A general bugfix; increments the Patch version unless suffixed with \`\!\`. - * \`chore\` - Small maintance related task, typically something that doesn't affect the source code. - * \`ci\` - For tasks relating to GitHub workflows and some minor gradle adjustments that affect the CI process. - * \`docs\` - Documentation only changes. - * \`test\` - Used when adding missing tests or adjusting existing tests. - * \`\!\` - Indicates this PR includes breaking changes, necessitating an increment of the Major version regardless of \`type\`. - * \`summary\` - A short one line summary of the PR. --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..38e50d1 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,31 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Build + +on: + push: + branches: [ main, release/** ] + pull_request: + branches: [ main, release/** ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6e7b84f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,27 @@ + +name: CI + +on: + push: + branches: [ main, release/** ] + pull_request: + branches: [ main, release/** ] + + workflow_dispatch: + +jobs: + + + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Build and Run Tests + uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Run tests with Maven + run: mvn -B test --file pom.xml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 350758e..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,39 +0,0 @@ - -name: CI - -# Controls when the workflow will run -on: - # Triggers the workflow on push or pull request events but only for the master branch - push: - branches: [ main ] - pull_request: - branches: [ main ] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -jobs: - - - test: - runs-on: ubuntu-latest - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v4 - - name: Build and Run Tests - uses: actions/cache@v4 - with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - name: Run tests with Maven - run: mvn -B test --file pom.xml - -# format: -# needs: test -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v4 -# - name: Google Java Format -# uses: axel-op/googlejavaformat-action@v3.4.0 diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yml similarity index 68% rename from .github/workflows/pr-check.yaml rename to .github/workflows/pr-check.yml index 885e30a..4df94c2 100644 --- a/.github/workflows/pr-check.yaml +++ b/.github/workflows/pr-check.yml @@ -3,11 +3,11 @@ on: pull_request: branches: - main - - releases/* + - release/** types: [ opened, reopened, edited, synchronize ] jobs: check-pr: - uses: ./.github/workflows/.reusable-common-pr-check.yaml + uses: ./.github/workflows/.common-pr-check.yml permissions: pull-requests: write diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..dff3185 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,147 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + type: string + description: Full version (major.minor.patch) number to release (example 1.2.3). + required: true + dry-run: + description: Dry run the release? Primary use is testing. + required: false + default: false + +run-name: "Release: ${{ inputs.version }}" + +jobs: + create-release: + env: + INTERNAL_REPO_URL: ${{ secrets.INTERNAL_REPO_URL }} + INTERNAL_REPO_USERNAME: ${{ secrets.INTERNAL_REPO_USERNAME }} + INTERNAL_REPO_PASSWORD: ${{ secrets.INTERNAL_REPO_PASSWORD }} + JAVA_VERSION: '17' + + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Validate version input + shell: bash + run: | + echo "Validating release version: ${{ github.event.inputs.version }}" + if [[ ! "${{ github.event.inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "ERROR: Invalid version input. Must be of the format major.minor.patch (e.g. 2.16.0)." + exit 1 + fi + + - name: Checkout Source + uses: actions/checkout@v4 + with: + clean: true + fetch-depth: 0 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: 'temurin' + cache: maven + + - name: Create Maven settings.xml + run: | + mkdir -p ~/.m2 + cat > ~/.m2/settings.xml < + + + internal-repo + ${INTERNAL_REPO_USERNAME} + ${INTERNAL_REPO_PASSWORD} + + + + + internal + + true + + + + internal-repo + ${INTERNAL_REPO_URL} + + + + + internal-repo + ${INTERNAL_REPO_URL} + + + + + + EOF + + - name: Deploy + if: ${{ github.event.inputs.dry-run != 'true' }} + run: mvn clean deploy -s ~/.m2/settings.xml + + - name: Does Tag Exist? + id: check_tag_exists + run: | + TAG="${{ github.event.inputs.version }}" + if git rev-parse "$TAG" >/dev/null 2>&1; then + echo "Tag $TAG already exists. Skipping tagging." + else + echo "should_tag=true" >> $GITHUB_OUTPUT + fi + + - name: Create Tag + if: steps.check_tag_exists.outputs.should_tag + id: create_tag + run: | + TAG="${{ github.event.inputs.version }}" + git tag $TAG + git push origin $TAG + + echo "TAG=$TAG" >> $GITHUB_OUTPUT + + - name: Build Changelog + id: changelog + if: steps.check_tag_exists.outputs.should_tag + run: | + CURRENT_TAG=${{ steps.create_tag.outputs.TAG }} + + # Get the previous tag (sorted by commit date, excluding current tag) + PREV_TAG=$(git tag --sort=-committerdate | grep -v "$CURRENT_TAG" | head -n 1) + + # If no previous tag exists, use the first commit + if [ -z "$PREV_TAG" ]; then + PREV_TAG=$(git rev-list --max-parents=0 HEAD) + fi + + # Get commit messages between the previous and current tag + CHANGELOG=$(git log --pretty="- %s (%h)" $PREV_TAG..$CURRENT_TAG) + + # Write changelog to environment file + echo "CHANGELOG<> $GITHUB_ENV + echo "$CHANGELOG" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - name: Create Release in GitHub + if: steps.check_tag_exists.outputs.should_tag + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ steps.create_tag.outputs.TAG }} + name: "Release ${{ steps.create_tag.outputs.TAG }}" + body: | + ## Release ${{ steps.create_tag.outputs.TAG }} + + ### Changes + ${{ env.CHANGELOG }} + draft: false + prerelease: false