-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This workflows runs only on prs tagged with 'Release'. It will generate the changelog and commit it to the pr. It will generate the next semver version based on given tags. It will also check if the app version was changed and if the current target sdk is higher than the assigned minimum.
- Loading branch information
1 parent
ff4ce95
commit efa7cfd
Showing
7 changed files
with
387 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}} |
Oops, something went wrong.