Skip to content

Commit

Permalink
UID2-2558 Use new commit and push workflow (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
cYKatherine authored Feb 27, 2024
1 parent c8a1133 commit b881383
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 45 deletions.
50 changes: 47 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Release
run-name: ${{ format('Release version {0}', inputs.version)}} by @${{ github.actor }}

on:
workflow_dispatch:
Expand All @@ -17,18 +18,28 @@ jobs:
runs-on: ubuntu-latest

permissions:
pull-requests: write
contents: write
security-events: write
packages: write

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Fail if Release and not on Default branch
if: ${{ github.event.repository.default_branch != github.ref_name }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('Releases can not be created on a feature branch. Branch: ${{ github.ref_name }}')
- name: Update Git user
run: |
git config --local user.name "IABTechLab"
Expand All @@ -42,14 +53,47 @@ jobs:
# Disable writing to cache. Don't want to spoil the main cache
cache-read-only: true

- name: Release
run: ./scripts/release.sh ${{ inputs.version }} ${{ inputs.snapshot }}
- name: Get Snaptshot versions
id: snapshotVersions
run: ./scripts/get_snapshot_versions.sh ${{ inputs.snapshot }}

- name: Prepare for release metadata
shell: bash
run: |
sed -i.bak "s/${{ steps.snapshotVersions.outputs.cur_snapshot_version }}/${{ inputs.version }}/g" gradle.properties
- name: Commit gradle.properties and set tag for v${{ inputs.version }}
uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v2
with:
add: 'gradle.properties'
message: 'Prepare for release: ${{ inputs.version }}'
tag: v${{ inputs.version }}

- name: Deploy v${{ inputs.version }}
run: ./gradlew publish
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_REPO_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_REPO_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }}

- name: Prepare next Snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }}
shell: bash
run: |
echo "Setting next snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }}"
sed -i.bak "s/${{ inputs.version }}/${{ steps.snapshotVersions.outputs.new_snapshot_version }}/g" gradle.properties
- name: Commit gradle.properties for Snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }}
uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v2
with:
add: 'gradle.properties'
message: 'Prepare next development version: ${{ steps.snapshotVersions.outputs.new_snapshot_version }}'

- name: Remove the backup file from sed edits
shell: bash
run: |
rm gradle.properties.bak
- name: GitHub Release
uses: softprops/action-gh-release@v1
with:
Expand Down
20 changes: 20 additions & 0 deletions scripts/get_snapshot_versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -exo pipefail

# Gets a property out of a .properties file
# usage: getProperty $key $filename
function getProperty() {
grep "${1}" "$2" | cut -d'=' -f2
}

NEW_SNAPSHOT_VERSION=$1
CUR_SNAPSHOT_VERSION=$(getProperty 'VERSION_NAME' gradle.properties)

if [ -z "$NEW_SNAPSHOT_VERSION" ]; then
# If no snapshot version was provided, use the current value
NEW_SNAPSHOT_VERSION=$CUR_SNAPSHOT_VERSION
fi

echo "new_snapshot_version=$NEW_SNAPSHOT_VERSION" >> $GITHUB_OUTPUT
echo "cur_snapshot_version=$CUR_SNAPSHOT_VERSION" >> $GITHUB_OUTPUT
42 changes: 0 additions & 42 deletions scripts/release.sh

This file was deleted.

0 comments on commit b881383

Please sign in to comment.