Skip to content

CI CheatSheet

Simon Seyock edited this page Jan 20, 2023 · 4 revisions

General

Jib

  • configure jib so it runs the build command on the maven target deploy or package. Only include plugin configs in the submodules that you want to actually publish. Then you can use corresponding target in the config of maven-semantic-release
  • Or use the targets deploy jib:build or package jib:build, then you have to include jib configs with the skip option in all submodules that you don't want to publish.

Gitlab

Github

Configure semantic-release

.releaserc.json

{
  "branches": [
    "main"
  ],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/changelog",
    [
      "@terrestris/maven-semantic-release",
      {
        "mavenTarget": "deploy",
        "clean": false,
        "updateSnapshotVersion": true,
        "settingsPath": "/home/runner/.m2/settings.xml", // the whelk-io/maven-settings-xml-action@v2 action creates the file here
        "processAllModules": true // only needed for multi-module projects
      }
    ],
    [
      "@semantic-release/git",
      {
        "assets": [
          "CHANGELOG.md", "pom.xml", "**/pom.xml" // `**/pom.xml` is only needed for multi-module projects
        ],
        "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
      }
    ],
    "@semantic-release/github"
  ]
}

Create workflow

Use a personal access token if you want to publish to protected branches and avoid certain limitations of the default GITHUB_TOKEN. See https://github.com/semantic-release/github#github-authentication and https://github.com/cycjimmy/semantic-release-action#basic-usage for more details.

.github/workflows/publish.yaml

on: workflow_dispatch

jobs:
  publish:
    runs-on: ubuntu-22.04

    steps:
    - name: Checkout sources
      uses: actions/checkout@v3
      with:
        fetch-depth: 0 # this is necessary for semantic-release
        persist-credentials: false # this is needed if using a personal access token (see below)

    - name: Set up Java 17
      uses: actions/[email protected]
      with:
        java-version: 17
        java-package: jdk
        architecture: x64

    - name: Restore cache
      uses: actions/cache/restore@v3
      with:
        path: ~/.m2/repository
        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
        restore-keys: |
          ${{ runner.os }}-maven-

    - name: Create maven settings.xml with credentials
      uses: whelk-io/maven-settings-xml-action@v2
      with:
        servers: |
          [
            # add server configs for publishing here, include all necessary passwords via secrets
          ]

    # This step is useful so the logs of the semantic-release step are not cluttered with download information
    - name: Install dependencies
      run: mvn compile --batch-mode

    # This is useful for testing semantic-release as the dependencies are cached before the semantic-release step fails
    - name: Save cache
      uses: actions/cache/save@v3
      with:
        path: ~/.m2/repository
        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}

    - name: Semantic release
      id: semantic
      uses: cycjimmy/semantic-release-action@v3
      with:
        semantic_version: 19 # Fixed versions are recommended so releases don't break the pipeline
        extra_plugins: |
          @semantic-release/changelog@6
          @terrestris/maven-semantic-release@2
          @semantic-release/git@10
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # use another name if you want to use a personal access token

    - name: Task that should be skipped if no new release was published
      if: steps.semantic.outputs.new_release_published == 'true'
      run: echo "test"

    - name: Save cache
      uses: actions/cache/save@v3
      with:
        path: ~/.m2/repository
        key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}

Run commitlint on pull_request (create .commitlintrc.json if needed)

.github/workflows/commitlint.yaml (or include in other workflow)

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  commitlint:

    runs-on: ubuntu-22.04

    steps:

      - name: Checkout sources
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - uses: wagoid/commitlint-github-action@v5
Clone this wiki locally