Skip to content

Commit

Permalink
build: update how changelogs work
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Dec 26, 2024
1 parent 4277775 commit 1c99cf8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
46 changes: 45 additions & 1 deletion .github/workflows/modrinth-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,50 @@ jobs:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout main branch from GitHub
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Restore last workflow commit from cache
id: cache-last-commit
uses: actions/cache@v4
with:
path: .last_workflow_commit
key: last-workflow-commit

- name: Get last workflow run commit
id: last_run
run: |
if [ -f .last_workflow_commit ]; then
LAST_COMMIT=$(cat .last_workflow_commit)
else
LAST_COMMIT=$(git rev-list --max-parents=0 HEAD)
fi
echo "LAST_COMMIT=$LAST_COMMIT" >> $GITHUB_ENV
- name: Count commits since last run
id: count_commits
run: |
COMMITS=$(git rev-list $LAST_COMMIT..HEAD --count)
echo "commits_count=$COMMITS" >> $GITHUB_ENV
echo "Number of commits since last run: $COMMITS"
- name: Use environment variables
run: |
echo "Last commit: $LAST_COMMIT"
echo "Number of commits: $commits_count"
- name: Store current commit for next run
run: |
git rev-parse HEAD > .last_workflow_commit
echo "Storing current commit: $(cat .last_workflow_commit)"
# Runs a single command using the runners shell
- name: Setting up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

Expand All @@ -30,4 +68,10 @@ jobs:
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
run: |
chmod +x gradlew
./gradlew :modrinth
./gradlew :modrinth
- name: Store current commit for next run
uses: actions/cache@v4
with:
path: .last_workflow_commit
key: last-workflow-commit
16 changes: 9 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,27 @@ modrinth {
}

fun getChangeLog(): String {
val currentBranch = grgit.branch.current().name
val remoteBranch = "origin/$currentBranch"
val lastCommitEnv = System.getenv("LAST_COMMIT")
?: return "The environment variable \$LAST_COMMIT is not defined."

val lastRemoteCommit = grgit.log {
range(remoteBranch, currentBranch)
}.lastOrNull()?.id ?: return "No se encontraron cambios desde el remoto."
val commitExists = grgit.log().any { it.id == lastCommitEnv }
if (!commitExists) {
return "The commit specified in \$LAST_COMMIT does not exist in this repository."
}

val changeLog = grgit.log {
range(lastRemoteCommit, currentBranch)
range(lastCommitEnv, "HEAD")
}

return if (changeLog.isNotEmpty()) {
changeLog.joinToString("\n") { commit ->
"- ${commit.shortMessage} (${commit.id})"
}
} else {
"No changes found."
"There are no changes since the commit specified in \$LAST_COMMIT."
}
}

tasks.modrinth {
dependsOn(tasks.shadowJar)
dependsOn(tasks.modrinthSyncBody)
Expand Down

0 comments on commit 1c99cf8

Please sign in to comment.