Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created new Changelog-Generator #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/app_sdk_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: AppVersionCheck

on:
workflow_call:
inputs:
app_gradle:
required: false
default: app/build.gradle
type: string
ref:
required: true
type: string
description: "The commit ref to checkout and compare against"
minTargetSdkVersion:
required: true
type: string
secrets:
token:
required: true

jobs:
sdk_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: "Getting the target sdk version"
id: version
run: |
echo targetSdkVersion=$(cat ${{ inputs.app_gradle }} | grep targetSdkVersion | awk '{print $2}') >> $GITHUB_OUTPUT
outputs:
targetSdkVersion: ${{ steps.version.outputs.targetSdkVersion }}

check_versions:
runs-on: ubuntu-latest
needs:
- sdk_version
steps:
- name: "Newer target sdk than ${{inputs.minTargetSdkVersion}}"
run: |
if [[ "${{ needs.sdk_version.outputs.targetSdkVersion }}" -lt "${{ inputs.minTargetSdkVersion }}" ]]; then
exit 1
fi
66 changes: 66 additions & 0 deletions .github/workflows/app_version_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: AppVersionCheck

on:
workflow_call:
inputs:
app_gradle:
required: false
default: app/build.gradle
type: string
ref:
required: true
type: string
description: "The commit ref to checkout and compare against"
secrets:
token:
required: true

jobs:
latest_release:
uses: ./.github/workflows/latest_version.yml
secrets:
token: ${{ secrets.token }}

old_app_version:
runs-on: ubuntu-latest
needs: latest_release
steps:
- uses: actions/checkout@v3
with:
ref: v${{ needs.latest_release.outputs.latest }}
- name: "Getting the old app version"
id: version
run: |
echo versionCode=$(cat ${{ inputs.app_gradle }} | grep versionCode | awk '{print $2}') >> $GITHUB_OUTPUT
echo versionName=$(cat ${{ inputs.app_gradle }} | grep versionName | awk '{print $2}') >> $GITHUB_OUTPUT
outputs:
versionCode: ${{ steps.version.outputs.versionCode }}
versionName: ${{ steps.version.outputs.versionName }}

new_app_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: "Getting the new app version"
id: version
run: |
echo versionCode=$(cat ${{ inputs.app_gradle }} | grep versionCode | awk '{print $2}') >> $GITHUB_OUTPUT
echo versionName=$(cat ${{ inputs.app_gradle }} | grep versionName | awk '{print $2}') >> $GITHUB_OUTPUT
outputs:
versionCode: ${{ steps.version.outputs.versionCode }}
versionName: ${{ steps.version.outputs.versionName }}

check_versions:
runs-on: ubuntu-latest
needs:
- old_app_version
- new_app_version
steps:
- name: "Same VersionCode"
if: ${{ needs.old_app_version.outputs.versionCode }} == ${{ needs.new_app_version.outputs.versionCode }}
run: exit 1
- name: "Same VersionName"
if: ${{ needs.old_app_version.outputs.versionName }} == ${{ needs.new_app_version.outputs.versionName }}
run: exit 1
55 changes: 43 additions & 12 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,54 @@
name: Changelog Generation
name: Create Changelog

on:
release:
types: [published, released]
workflow_dispatch:
workflow_call:
inputs:
ref:
required: true
type: string
version:
required: true
type: string
description: The next version tag
secrets:
token:
required: true
outputs:
changelog:
value: ${{ jobs.changelog.outputs.changelog }}
description: The identifier for the artifact

jobs:
changelog:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
name: "Checkout ${{ inputs.ref }}"
with:
ref: ${{ inputs.ref }}
submodules: 'recursive'
ref: master
- uses: rhysd/changelog-from-release/action@v3
- name: "Current Date"
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: "Get PR body"
id: body
run: echo body=$(echo "${{github.event.pull_request.body}}" | sed -e 's/Release-Version:.*//') >> $GITHUB_OUTPUT
- uses: heinrichreimer/[email protected]
name: "Generate Changelog"
with:
token: ${{ secrets.token }}
output: "CHANGELOG.md"
- name: "Change Unreleased: to new version ${{ inputs.version }}"
run: |
sed -e 's/\[Unreleased\](https:\/\/github.com\/SecUSo\/privacy-friendly-shopping-list\/tree\/HEAD)/[${{ inputs.version }}](https:\/\/github.com\/SecUSo\/privacy-friendly-shopping-list\/tree\/v${{needs.next_version.outputs.next}}) (${{steps.date.outputs.date}})/' CHANGELOG.md > /tmp/CHANGELOG.md
mv /tmp/CHANGELOG.md CHANGELOG.md
- name: Upload Changelog
uses: actions/upload-artifact@master
with:
file: CHANGELOG.md
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_summary_template: 'update changelog for %s changes'
args: -l 2
header: |
# Changelog
name: Changelog
path: CHANGELOG.md

outputs:
changelog: Changelog

76 changes: 76 additions & 0 deletions .github/workflows/create_release_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Changelog Generation

on:
pull_request:

jobs:

next_version:
if: ${{ contains(github.event.pull_request.labels.*.name, 'Release') }}
uses: ./.github/workflows/next_version.yml
secrets:
token: ${{ secrets.GITHUB_TOKEN }}

app_version_check:
if: ${{ contains(github.event.pull_request.labels.*.name, 'Release') }}
uses: ./.github/workflows/app_version_check.yml
with:
ref: ${{ github.event.pull_request.head.ref }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}

sdk_version_check:
if: ${{ contains(github.event.pull_request.labels.*.name, 'Release') }}
uses: ./.github/workflows/app_sdk_check.yml
with:
ref: ${{ github.event.pull_request.head.ref }}
minTargetSdkVersion: ${{ vars.MIN_TARGET_SDK }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}

changelog:
if: ${{ contains(github.event.pull_request.labels.*.name, 'Release') }}
uses: ./.github/workflows/changelog.yml
needs: next_version
with:
ref: ${{ github.event.pull_request.head.ref }}
version: v${{ needs.next_version.outputs.next }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}

finalize:
if: ${{ contains(github.event.pull_request.labels.*.name, 'Release') }}
runs-on: ubuntu-latest
needs:
- next_version
- app_version_check
- sdk_version_check
- changelog
steps:
- uses: actions/checkout@v3
name: "Checkout ${{ inputs.ref }}"
with:
ref: ${{ inputs.ref }}
submodules: 'recursive'
- uses: actions/download-artifact@master
with:
name: ${{ needs.changelog.outputs.changelog }}
path: CHANGELOG.md
- name: "Pushing Changelog"
run: |
version=v${{ needs.next_version.outputs.next }}

git add "CHANGELOG.md"
git config --global user.name "Action-Changelog-Generator"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
if git commit -m "[Action] generated changelog for $version"; then
git tag -d "$version" || true
git tag "$version"
git push
fi
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: "Append version ${{ needs.next_version.outputs.next }}"
uses: AsasInnab/pr-body-action@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
body: "${{steps.body.outputs.body}}\n\nRelease-Version: ${{ needs.next_version.outputs.next }}. [Changelog](../blob/${{ steps.changelog.outputs.commit }}/CHANGELOG.md)"
29 changes: 29 additions & 0 deletions .github/workflows/latest_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Get current version

on:
workflow_call:
outputs:
latest:
description: "The latest version number in x.y.z notation"
value: ${{ jobs.version.outputs.latest }}
secrets:
token:
required: true

jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: InsonusK/[email protected]
name: "Retreiving the last version number"
id: v
with:
myToken: ${{ secrets.token }}
excludeTypes: "prerelease|draft"
- id: out
run: |
latest=$(echo ${{ steps.v.outputs.tag_name }} | grep -Po '[0-9]+\.[0-9]+\.[0-9]+')
echo "latest=$latest" >> $GITHUB_OUTPUT
outputs:
latest: ${{ steps.out.outputs.latest }}
42 changes: 42 additions & 0 deletions .github/workflows/next_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Generate next version

on:
workflow_call:
outputs:
next:
description: "The next version number in x.y.z notation"
value: ${{ jobs.next_version.outputs.next }}
secrets:
token:
required: true

jobs:
version:
uses: ./.github/workflows/latest_version.yml
secrets:
token: ${{ secrets.token }}

next_version:
runs-on: ubuntu-latest
needs: version
steps:
- id: next
run: |
latest=${{ needs.version.outputs.latest }}
major=$(echo $latest | awk -F '.' '{print $1}' )
normal=$(echo $latest | awk -F '.' '{print $2}' )
minor=$(echo $latest | awk -F '.' '{print $3}' )

tags=(${{join(github.event.pull_request.labels.*.name, ' ')}})
if [[ "${tags[*]}" =~ 'Major' ]]; then
next=$((1 + major)).0.0
elif [[ "${tags[*]}" =~ 'Minor' ]]; then
next=$major.$normal.$((1 + minor))
else
next=$major.$((1 + normal)).0
fi

echo "next=$next" >> $GITHUB_OUTPUT

outputs:
next: ${{steps.next.outputs.next}}
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## [Unreleased](https://github.com/SecUSo/privacy-friendly-shopping-list/tree/HEAD)
## [v1.0.10](https://github.com/SecUSo/privacy-friendly-shopping-list/tree/v1.0.10) (2023-01-14)

[Full Changelog](https://github.com/SecUSo/privacy-friendly-shopping-list/compare/v1.0.9...HEAD)

Expand Down