Skip to content

Commit

Permalink
feat: Automatic release
Browse files Browse the repository at this point in the history
- Use semantic-release to help with automatic releases. This will create
  semver releases. Therefore, the versions
  will differ more from the wiremock version.
- Configure GitHub release formatting
- Configure GitHub labeler
- Reduce action runs on pushes
- Adjust gradle build to use the semver
- Add major and minor tags automatically
  • Loading branch information
holomekc committed Apr 1, 2024
1 parent 3151de3 commit d6a37e5
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 73 deletions.
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
* text eol=lf
# This file is broken and makes not sense as it is specified.
# It breaks the usage of git on linux based systems. Ignore crlf files
# which cannot be converted to lf. E.g. gradle wrapper conversion brakes
# the validation.
gradlew.bat -text
*.png -text
gradle-wrapper.jar -text
sample-war/src/main/webapp/WEB-INF/wiremock/__files/mytest.json -text
sample-war/src/main/webapp/WEB-INF/wiremock/mappings/mytest-mapping.json -text
src/test/resources/not-found-diff-sample_large_xml_jre11_windows.txt -text
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ updates:
update-types:
- "minor"
- "patch"
commit-message:
prefix: "chore(deps)"
- package-ecosystem: docker
directory: "/"
schedule:
Expand All @@ -31,3 +33,5 @@ updates:
open-pull-requests-limit: 20
assignees:
- Author
commit-message:
prefix: "chore(deps)"
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bug:
- head-branch: ['^fix']
enhancement:
- head-branch: ['^feat']
33 changes: 33 additions & 0 deletions .github/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
changelog:
exclude:
labels:
- ignore-for-release
categories:
- title: 🚨 Security Updates
labels:
- security
- title: 🛠 Breaking Changes
labels:
- breaking
- title: 📦 Dependency updates
labels:
- dependencies
- title: 🐛 Bug fixes
labels:
- bug
- title: 🎉 New Features
labels:
- enhancement
- title: 🧪 Test Updates
labels:
- test
- title: 📖 Documentation
labels:
- documentation
- title: 🚧 Build Tools
labels:
- ci
- build
- title: ℹ️ Other Changes
labels:
- "*"
2 changes: 0 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
name: Build and Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

Expand Down
102 changes: 73 additions & 29 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
name: Create Release

on:
push:
tags:
- "*-ui"
schedule:
- cron: "0 9 * * *"
workflow_dispatch:

env:
SEMANTIC_RELEASE_VERSION: 23.0.6
SEMANTIC_RELEASE_EXEC_VERSION: 6.0.3
CONVENTIONAL_COMMITS_VERSION: 7.0.2

jobs:
build:
Expand All @@ -25,56 +30,95 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set output
id: vars
run: |
echo "tag=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_OUTPUT
echo "version=$(echo $GITHUB_REF | cut -d / -f 3 | sed 's/.\{3\}$//')" >> $GITHUB_OUTPUT
- name: Check output
run: |
echo ${{ steps.vars.outputs.tag }}
echo ${{ steps.vars.outputs.version }}

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v2

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Cache node modules
uses: actions/cache@v4
id: cache-node-modules
with:
path: ~/.npm
key: ${{ runner.os }}-release-${{ env.SEMANTIC_RELEASE_VERSION }}-${{ env.SEMANTIC_RELEASE_EXEC_VERSION }}-${{ env.CONVENTIONAL_COMMITS_VERSION }}

- name: Install Dependencies
shell: bash
run: |
#!/bin/bash
npm install -g semantic-release@${{ env.SEMANTIC_RELEASE_VERSION }} \
@semantic-release/exec@${{ env.SEMANTIC_RELEASE_EXEC_VERSION }} \
conventional-changelog-conventionalcommits@${{ env.CONVENTIONAL_COMMITS_VERSION }}
- name: Determine Semver & Update PRs and Issues
id: semver
env:
GH_TOKEN: ${{ github.token }}
FORCE_COLOR: 1
DEBUG_COLORS: 1
run: |
#!/bin/bash
semantic-release --debug
- name: Set up JDK
uses: actions/setup-java@v4
if: steps.semver.outputs.version != ''
with:
java-version: ${{ matrix.jdk }}
distribution: 'temurin'

- name: Grant execute permission for gradlew
if: steps.semver.outputs.version != ''
run: chmod +x gradlew

- name: Cache Gradle packages
uses: actions/cache@v4
if: steps.semver.outputs.version != ''
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle

- name: Build
run: ./gradlew jar shadowJar
if: steps.semver.outputs.version != ''
run: ./gradlew jar shadowJar -PprojVersion=${{ steps.semver.outputs.version }}

- name: Create Release
id: create_release
uses: actions/create-release@v1
id: create-release
shell: bash
if: steps.semver.outputs.version != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.vars.outputs.tag }}
release_name: ${{ steps.vars.outputs.version }}
body_path: RELEASE-NOTES.md
draft: false
prerelease: false
GH_TOKEN: ${{ github.token }}
run: |
#!/bin/bash
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/releases \
-f tag_name='${{ steps.semver.outputs.version }}' \
-f target_commitish='${{ github.sha }}' \
-f name='${{ steps.semver.outputs.version }}' \
-F draft=false \
-F prerelease=false \
-F generate_release_notes=true
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./build/libs/wiremock-standalone-${{ steps.vars.outputs.version }}.jar
asset_name: wiremock-standalone-${{ steps.vars.outputs.version }}.jar
asset_content_type: application/java-archive
GH_TOKEN: ${{ github.token }}
shell: bash
if: steps.semver.outputs.version != ''
run: |
gh release upload ${{ steps.semver.outputs.version }} ./build/libs/wiremock-standalone-${{ steps.semver.outputs.version }}.jar#wiremock-standalone-${{ steps.semver.outputs.version }}.jar
docker:
needs: [build]
uses: ./.github/workflows/docker-release.yml
if: needs.build.outputs.version != ''
with:
version: ${{ needs.build.outputs.version }}
secrets:
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/docker-image-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
id: extract-version
run: |
tag=${{ steps.extract-release.outputs.release }}
version=${tag%-*}
version=${tag}
echo $version
echo "version=${version}" >> $GITHUB_OUTPUT
Expand All @@ -48,10 +48,8 @@ jobs:
name: Ignore some policies
run: |
cat > .trivyignore << EOL
# Ignore gosu issue. They say they are not affected. Issue will be removed as soon
# as wiremock image updates to a newer gosu version, which removed runc.
CVE-2023-27561
CVE-2024-21626
# Ignore false-positives like this:
# CVE-2023-27561
EOL
- uses: actions/cache@v4
with:
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Pull Request Labeler"
on:
pull_request:
branches-ignore:
# dependabot labels automatically already
- dependabot/**

jobs:
labeler:
name: Label Pull requests
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
env:
GH_TOKEN: ${{ github.token }}
with:
sync-labels: true
33 changes: 0 additions & 33 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/validate-gradle-wrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
name: Validate Gradle wrapper

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

Expand Down
44 changes: 44 additions & 0 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
branches: [ "master" ]
repositoryUrl: "[email protected]:holomekc/wiremock.git"
tagFormat: ${version}
plugins:
# https://github.com/semantic-release/semantic-release/blob/master/docs/extending/plugins-list.md
- "@semantic-release/commit-analyzer"
- "@semantic-release/exec"
- "@semantic-release/github"
dryRun: false
ci: true

analyzeCommits:
# https://github.com/semantic-release/commit-analyzer
- path: "@semantic-release/commit-analyzer"
preset: "conventionalcommits"
# Default rules: https://github.com/semantic-release/commit-analyzer/blob/master/lib/default-release-rules.js
# releaseRules:
# - type: "feat"
# release: "patch"

verifyRelease:
- path: "@semantic-release/exec"
verifyReleaseCmd: |
#!/bin/bash
echo "version=${nextRelease.version}" >> "$GITHUB_OUTPUT" || echo "Most likely no ci env. Skipping export of ${nextRelease.version}"
generateNotes: false
publish: false

success:
- path: "@semantic-release/exec"
successCmd: |
#!/bin/bash
./release-tags.sh "${nextRelease.version}"
- path: "@semantic-release/github"
successComment: |
:tada: This <%= issue.pull_request ? 'pull request' : 'issue' %> is included in version <%= '[' + nextRelease.version + '](https://github.com/holomekc/wiremock/releases/tag/' + nextRelease.version + ')' %>
fail:
- path: "@semantic-release/github"
labels: false
assignees:
- "@holomekc"
2 changes: 1 addition & 1 deletion alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM wiremock/wiremock:latest-alpine
FROM wiremock/wiremock:3.5.2-1-alpine

LABEL maintainer="Christopher Holomek <[email protected]>"
LABEL org.label-schema.name="wiremock-gui"
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ allprojects {
mavenCentral()
}

version = '3.4.2.0'
if (project.hasProperty('projVersion')) {
version = project.projVersion
} else {
version = '1.0.0-Snapshot'
}


sourceCompatibility = 11
Expand Down
11 changes: 11 additions & 0 deletions release-tags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
major=$(echo "${1}" | cut -d. -f1)
minor=$(echo "${1}" | cut -d. -f2)

echo "Update minor tag: ${major}.${minor}"
git tag "${major}.${minor}" --force
git push origin "${major}.${minor}" --force

echo "Update major tag: ${major}"
git tag "${major}" --force
git push origin "${major}" --force

0 comments on commit d6a37e5

Please sign in to comment.