Skip to content
Closed
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
39 changes: 39 additions & 0 deletions .github/workflows/refresh-catalog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Refresh Catalog

on:
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
refresh-catalog:
name: Refresh central catalog copy
runs-on: ubuntu-latest

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

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
cache: gradle

- name: Refresh catalog
run: ./gradlew --no-daemon refreshCatalog

- name: Open pull request
uses: peter-evans/create-pull-request@v7
with:
branch: automation/refresh-central-catalog
delete-branch: true
commit-message: Refresh central Gradle version catalog
title: Refresh central Gradle version catalog
body: |
Updates the local Gradle version catalog from NostrGameEngine/libs.catalog.

If the downloaded catalog is identical to the current file, this workflow exits without opening a pull request.
3 changes: 3 additions & 0 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: publish-snapshots

on:
workflow_dispatch:
schedule:
- cron: '07 4 * * 0'
push:
pull_request:

Expand Down
18 changes: 18 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,21 @@ nexusPublishing {
}
}
}

tasks.register('refreshCatalog') {
group = 'build setup'
description = 'Downloads the central NostrGameEngine Gradle version catalog.'

def catalogUrl = providers.gradleProperty('centralCatalogUrl')
.orElse('https://raw.githubusercontent.com/NostrGameEngine/libs.catalog/main/libs.versions.toml')
def outputFile = layout.projectDirectory.file('gradle/libs.versions.toml')

outputs.file(outputFile)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Because gradle/libs.versions.toml is committed to the repository, it will always exist. Since this task defines an output file but no inputs, Gradle's up-to-date check will consider the task UP-TO-DATE and skip execution on subsequent runs, preventing the catalog from actually being refreshed.

To ensure the catalog is always refreshed when this task is explicitly executed, configure the task to never be considered up-to-date by adding outputs.upToDateWhen { false }.

    outputs.file(outputFile)
    outputs.upToDateWhen { false }


doLast {
def target = outputFile.asFile
target.parentFile.mkdirs()
target.text = new URI(catalogUrl.get()).toURL().getText('UTF-8')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are two potential issues with the current file download and write implementation:

  1. Missing Timeouts: URL.getText(String) does not have a default timeout, which can cause the Gradle build to hang indefinitely if the network connection is flaky or the remote server is unresponsive.
  2. Platform-Default Encoding: Assigning a string directly to target.text uses the platform's default encoding to write the file. This can lead to encoding discrepancies or corruption of non-ASCII characters when run on different operating systems (e.g., Windows vs. Linux).

Using URL.getText(Map, String) with explicit connectTimeout and readTimeout parameters, and writing the file using target.setText(text, charset) ensures both network resilience and platform-independent UTF-8 encoding.

        target.setText(new URI(catalogUrl.get()).toURL().getText(connectTimeout: 10000, readTimeout: 10000, 'UTF-8'), 'UTF-8')

println "Refreshed ${target}"
}
}
Loading
Loading