diff --git a/.github/workflows/app_sdk_check.yml b/.github/workflows/app_sdk_check.yml new file mode 100644 index 00000000..8ef6f83d --- /dev/null +++ b/.github/workflows/app_sdk_check.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/app_version_check.yml b/.github/workflows/app_version_check.yml new file mode 100644 index 00000000..5c536f06 --- /dev/null +++ b/.github/workflows/app_version_check.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index ad4099a7..063919c7 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -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/action-github-changelog-generator@v2.3 + 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 + \ No newline at end of file diff --git a/.github/workflows/create_release_pr.yml b/.github/workflows/create_release_pr.yml new file mode 100644 index 00000000..936be9dd --- /dev/null +++ b/.github/workflows/create_release_pr.yml @@ -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)" diff --git a/.github/workflows/latest_version.yml b/.github/workflows/latest_version.yml new file mode 100644 index 00000000..a8e4fcfd --- /dev/null +++ b/.github/workflows/latest_version.yml @@ -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/get-latest-release@v1.0.1 + 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 }} \ No newline at end of file diff --git a/.github/workflows/next_version.yml b/.github/workflows/next_version.yml new file mode 100644 index 00000000..47f91f74 --- /dev/null +++ b/.github/workflows/next_version.yml @@ -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}} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bf11a22..667fd491 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)