Skip to content

Snapshot Release

Snapshot Release #1

name: Snapshot Release
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
permissions:
contents: write
issues: write
pull-requests: write
concurrency:
group: snapshot-${{ github.ref }}
cancel-in-progress: true
jobs:
changes:
name: Check for Changes
runs-on: ubuntu-latest
outputs:
has_changes: ${{ steps.changes.outputs.has_changes }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect recent changes
id: changes
shell: bash
run: |
set -euo pipefail
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
echo "Manual run - proceeding regardless of recent changes."
echo "has_changes=true" >> "$GITHUB_OUTPUT"
exit 0
fi
files=$(git log --since="24 hours ago" --name-only --pretty=format: | sort -u)
if [ -z "${files:-}" ]; then
echo "No commits in the last 24 hours."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
filtered=$(echo "$files" | grep -vE '(^docs/|\.md$|^\.github/workflows/deploy-gh-pages\.yml$)' || true)
if [ -z "${filtered:-}" ]; then
echo "Only ignored paths changed in the last 24 hours."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "Changes detected in the last 24 hours:"
echo "$filtered"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
snapshot-release:
name: Publish Snapshot Release
runs-on: ubuntu-latest
needs: changes
if: ${{ github.repository_owner == 'hdcodedev' && needs.changes.outputs.has_changes == 'true' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu'
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Get snapshot version from lib/build.gradle.kts
id: version
run: |
set -euo pipefail
BUILD_FILE="lib/build.gradle.kts"
if [ ! -f "$BUILD_FILE" ]; then
echo "Build file not found: $BUILD_FILE" >&2
exit 1
fi
SNAPSHOT_VERSION=$(grep -E '^\s*version\s*=\s*"' "$BUILD_FILE" | sed -E 's/.*"([^"]+)".*/\1/' | tr -d '\r' | xargs)
if [ -z "${SNAPSHOT_VERSION:-}" ]; then
echo "Failed to parse version from $BUILD_FILE" >&2
exit 1
fi
if [[ "$SNAPSHOT_VERSION" != *"-SNAPSHOT"* ]]; then
echo "⏭️ Skipping snapshot release - version is not a SNAPSHOT: ${SNAPSHOT_VERSION}"
echo "is_snapshot=false" >> "$GITHUB_OUTPUT"
else
echo "is_snapshot=true" >> "$GITHUB_OUTPUT"
fi
echo "snapshot_version=${SNAPSHOT_VERSION}" >> "$GITHUB_OUTPUT"
echo "Version: ${SNAPSHOT_VERSION}"
- name: Check required secrets
if: ${{ steps.version.outputs.is_snapshot == 'true' }}
id: secrets_check
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SIGNING_IN_MEMORY_KEY: ${{ secrets.SIGNING_IN_MEMORY_KEY }}
shell: bash
run: |
set -euo pipefail
missing=0
for v in MAVEN_CENTRAL_USERNAME MAVEN_CENTRAL_PASSWORD SIGNING_KEY_ID SIGNING_PASSWORD SIGNING_IN_MEMORY_KEY; do
if [ -z "${!v:-}" ]; then
echo "Missing secret: $v" >&2
missing=1
fi
done
if [ "$missing" -eq 0 ]; then
echo "can_publish=true" >> "$GITHUB_OUTPUT"
else
echo "can_publish=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish snapshot to Maven Central
if: ${{ steps.version.outputs.is_snapshot == 'true' && steps.secrets_check.outputs.can_publish == 'true' }}
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_IN_MEMORY_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
run: |
echo "Publishing snapshot version: ${{ steps.version.outputs.snapshot_version }}"
cd lib && ./gradlew publish --no-daemon --stacktrace
- name: Comment on commit
if: ${{ steps.version.outputs.is_snapshot == 'true' && steps.secrets_check.outputs.can_publish == 'true' }}
uses: actions/github-script@v7
with:
script: |
const version = process.env.SNAPSHOT_VERSION;
const message = [
'🚀 **Snapshot Release Published**',
'',
`Version: \`${version}\``,
'',
'The snapshot is now available on Maven Central Snapshots repository.',
'',
'Add the snapshot repository to your project:',
'```kotlin',
'repositories {',
' maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")',
'}',
'```',
'',
'Apply the plugin in your `build.gradle.kts`:',
'```kotlin',
'plugins {',
` id("io.github.hdcodedev.compose-gif-recorder") version "${version}"`,
'}',
'```',
'',
'The plugin automatically adds all required dependencies (`annotations`, `core`, `android`, `ksp`).',
].join('\n');
await github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: message
})