Skip to content

Automated release #17

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

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions .github/actions/publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ runs:
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
ref: master
fetch-depth: 0

- name: publish
shell: bash
Expand Down
51 changes: 0 additions & 51 deletions .github/actions/release/action.yml

This file was deleted.

66 changes: 54 additions & 12 deletions .github/actions/version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,73 @@ runs:
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
branch: master
ref: master

- name: Bump version
- uses: codfish/semantic-release-action@v3
with:
additional-packages: |
['@semantic-release/git', '@semantic-release/exec']

- name: NEW_RELEASE_PUBLISHED check
shell: bash
id: version
run: |
./gradlew bumpPatchVersion --no-configuration-cache
if [ "${NEW_RELEASE_PUBLISHED}" != "true" ]; then
echo "New release not published, exit"
exit 1
fi

- name: Retrieve version
shell: bash
id: versionName
env:
FILE_PATH: ./build.gradle.kts
id: versionNameStep
run: |
version=$(grep -o "version='[^']*'" $FILE_PATH | head -1 | cut -d"'" -f2)
echo "versionName=$version" >> $GITHUB_ENV
version=$(./gradlew -q printVersion --no-configuration-cache)
echo "versionName=$version" >> $GITHUB_OUTPUT

- name: Create new branch
id: newBranchNameStep
shell: bash
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
branch=release/${{ steps.versionNameStep.outputs.versionName }}
echo "branchName=$branch" >> $GITHUB_OUTPUT
git checkout -b $branch
git push --set-upstream origin $branch

- name: Get last merged PR author login
shell: bash
id: pr_author
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
PR_NUMBER=$(gh pr list --state merged --limit 1 --json number --jq '.[0].number')
LAST_PR_AUTHOR=$(gh pr view $PR_NUMBER --json author --jq '.author.login')
echo "lastPrAuthor=$LAST_PR_AUTHOR" >> $GITHUB_OUTPUT

- name: Commit changes
id: committer
uses: planetscale/[email protected]
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
with:
repo: ${{ github.repository }}
branch: master
commit_message: "chore(common): version bump to ${{ steps.versionName.outputs.versionName }}"
file_pattern: "personalization-sdk"
branch: ${{ steps.newBranchNameStep.outputs.branchName }}
commit_message: "chore(common): version bump to ${{ steps.versionNameStep.outputs.versionName }}"
file_pattern: "version.properties"

- name: Create Pull Request
shell: bash
working-directory: ${{ inputs.targetDirectory }}
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
BRANCH_NAME: ${{ steps.newBranchNameStep.outputs.branchName }}
LAST_PR_AUTHOR: ${{ steps.pr_author.outputs.lastPrAuthor }}
# TODO change it
REVIEWER: iwwwanow
run: |
PR_TITLE="Automated release"
PR_BODY="This is an automated pull request to update from branch $BRANCH_NAME"
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef -q ".defaultBranchRef.name")
echo "Assigning PR to LAST_PR_AUTHOR: $LAST_PR_AUTHOR"
echo "Adding REVIEWER: $REVIEWER as a reviewer"
gh pr create --title "$PR_TITLE" --body "$PR_BODY" --base "$DEFAULT_BRANCH" --head $BRANCH_NAME --assignee $LAST_PR_AUTHOR --reviewer $REVIEWER
27 changes: 4 additions & 23 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
name: Patch version, publish to GitHubPackages and create new GitHub release
name: Publish

on:
pull_request:
types:
- closed
branches:
- master
paths-ignore:
- ".github/**"
- "release/**"
workflow_dispatch:

jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: rees/kmp/.github/actions/version@master
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
with:
appId: ${{ vars.PUBLIVERSIONER_ID }}
appSecret: ${{ secrets.PUBLIVERSIONER_SECRET }}

publish:
needs: version
runs-on: ubuntu-latest
steps:
- uses: rees/kmp/.github/actions/publish@master
- uses: rees46/kmp/.github/actions/publish@master
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
with:
appId: ${{ vars.PUBLIVERSIONER_ID }}
appSecret: ${{ secrets.PUBLIVERSIONER_SECRET }}
githubToken: ${{ secrets.GITHUB_TOKEN }}

release:
needs: [publish, version]
runs-on: ubuntu-latest
steps:
- uses: rees/kmp/.github/actions/release@master
with:
appId: ${{ vars.PUBLIVERSIONER_ID }}
appSecret: ${{ secrets.PUBLIVERSIONER_SECRET }}
32 changes: 32 additions & 0 deletions .github/workflows/repo-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Repository synchronization

on:
pull_request:
types:
- closed
branches:
- master
workflow_dispatch:

jobs:
prepare:
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
outputs:
replacements: ${{ steps.getReplacementsStep.outputs.replacements }}
steps:
- uses: rees46/shared/.github/actions/sync/read-replacements@master
id: getReplacementsStep

repoSync:
needs: prepare
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
uses: rees46/shared/.github/workflows/repo-sync.yaml@master
secrets:
appSecret: ${{ secrets.REES46_PUBLISHER_SECRET }}
with:
appId: ${{ vars.REES46_PUBLISHER_ID }}
replacements: ${{ needs.prepare.outputs.replacements }}
repositoryOwner: rees46
reviewerUsername: iwwwanow
targetRepository: rees46/kmp
22 changes: 22 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Bump version

on:
pull_request:
types:
- closed
branches:
- master
- "!release/**"
paths-ignore:
- ".github/**"
workflow_dispatch:

jobs:
version:
runs-on: ubuntu-latest
steps:
- uses: rees46/kmp/.github/actions/version@master
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
with:
appId: ${{ vars.PUBLIVERSIONER_ID }}
appSecret: ${{ secrets.PUBLIVERSIONER_SECRET }}
22 changes: 22 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
# "branches": ["master"],
"branches": ["refactor/version"],
"plugins":
[
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/git",
{
"assets": ["version.properties"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
},
],
[
"@semantic-release/exec",
{
"prepareCmd": "./gradlew updateVersion -PnewVersion=${nextRelease.version} --no-configuration-cache",
},
],
],
}
37 changes: 21 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ repositories {
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

val versionFile = file("version.properties")
val projectVersion = versionFile.readText().substringAfter("version=").trim()

allprojects {
group = "com.rees46"
version = "1.0.3"
version = projectVersion

apply(plugin = "maven-publish")
apply(plugin = "signing")
Expand Down Expand Up @@ -104,22 +107,24 @@ subprojects {
}
}

tasks.register("bumpPatchVersion") {
doNotTrackState("Modifies build files")

doLast {
val (major, minor, patch) = version.toString().split(".").map { it.toInt() }
val newVersion = "$major.$minor.${patch + 1}"

val buildFile = file("build.gradle.kts")
val content =
buildFile
.readText()
.replace(Regex("version\\s*=\\s*[\"']$version[\"']"), "version = \"$newVersion\"")
tasks.register("printVersion") {
doLast {
println(version)
}
}

buildFile.writeText(content)
println("Version updated from $version to $newVersion")
}
tasks.register("updateVersion") {
doLast {
val newVersion = project.property("newVersion") as String

file("version.properties").writeText("version=$newVersion")

allprojects {
version = newVersion
}

println("Version updated to $newVersion")
}
}

nexusPublishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
id("com.atls.compose") version "1.0.0"
id("com.rees46.compose") version "1.0.0"
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
id("com.atls.multiplatform") version "1.0.0"
id("com.rees46.multiplatform") version "1.0.0"
}

kotlin {
Expand Down
1 change: 1 addition & 0 deletions version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=1.1.2