diff --git a/.github/changelog_config.json b/.github/changelog_config.json new file mode 100644 index 0000000..99bc2f2 --- /dev/null +++ b/.github/changelog_config.json @@ -0,0 +1,18 @@ +{ + "categories": [ + { + "title": "## 🔨 Fixes and Improvements", + "labels": [ + "bug", + "enhancement" + ] + } + ], + "ignore_labels": [], + "template": "${{CHANGELOG}}\n---\n${{UNCATEGORIZED}}", + "pr_template": "- ${{TITLE}} (PR: #${{NUMBER}})", + "empty_template": "- no changes", + "label_extractor": [], + "transformers": [], + "exclude_merge_branches": [] +} \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..bbc9c8d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,63 @@ +name: Publish + +on: + push: + tags: + - "*" + +jobs: + unit_test: + name: Run Unit Tests + uses: ./.github/workflows/unit-test.yml + + publish_to_maven_central: + name: Publish to Maven Central Repository + needs: + - unit_test + runs-on: ubuntu-latest + environment: production + timeout-minutes: 15 + steps: + - uses: actions/checkout@v4.1.1 + + - name: Publish to Maven Central Staging Repository + env: + LIBRARY_RELEASE_MODE: true + MAVEN_CENTRAL_USER: ${{ secrets.MAVEN_CENTRAL_USER }} + MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + RELEASE_SIGNING_KEY_ID: ${{ secrets.RELEASE_SIGNING_KEY_ID }} + RELEASE_SIGNING_KEY: ${{ secrets.RELEASE_SIGNING_KEY }} + RELEASE_SIGNING_KEY_PASSWORD: ${{ secrets.RELEASE_SIGNING_KEY_PASSWORD }} + run: ./gradlew scratchoff:publishReleasePublicationToMavenCentralRepository + + create_release_for_tag: + name: Create Github Release + needs: + - publish_to_maven_central + runs-on: ubuntu-latest + timeout-minutes: 15 + environment: production + steps: + - uses: actions/checkout@v4.1.1 + + - name: Generate Github App Token for Release Creation Access + uses: tibdex/github-app-token@v2.1.0 + id: generate_release_token + with: + app_id: ${{ secrets.APP_RELEASES_APP_ID }} + private_key: ${{ secrets.APP_RELEASES_APP_PRIVATE_KEY }} + + - name: Generate Changelog for Release Body + id: generate_changelog + uses: mikepenz/release-changelog-builder-action@v4.1.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + configuration: ".github/changelog_config.json" + toTag: ${{ github.sha }} + + - name: Create Release For Tag + uses: ncipollo/release-action@v1.13.0 + with: + token: ${{ steps.generate_release_token.outputs.token }} + body: ${{ steps.generate_changelog.outputs.changelog }} diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 9d273bd..09b4b46 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -10,6 +10,7 @@ jobs: unit_test: name: Run Unit Tests runs-on: ubuntu-latest + timeout-minutes: 15 steps: - name: Checkout uses: actions/checkout@v4.1.1 diff --git a/scratchoff/build.gradle b/scratchoff/build.gradle index 744af0e..782ff62 100644 --- a/scratchoff/build.gradle +++ b/scratchoff/build.gradle @@ -30,6 +30,13 @@ android { returnDefaultValues = true } } + + publishing { + singleVariant('release') { + withSourcesJar() + withJavadocJar() + } + } } dependencies { diff --git a/scratchoff/publishing.gradle b/scratchoff/publishing.gradle index acdeca3..57d5c68 100644 --- a/scratchoff/publishing.gradle +++ b/scratchoff/publishing.gradle @@ -1,13 +1,4 @@ -def localPropertiesFile = new File(project.rootProject.getRootDir(), 'local.properties') - -if (!localPropertiesFile.exists()) { - return -} - -Properties localProperties = new Properties() -localProperties.load(localPropertiesFile.newDataInputStream()) - -if (localProperties.getProperty("release_mode", "false") != "true") { +if (System.getenv("LIBRARY_RELEASE_MODE") != "true") { return } @@ -33,36 +24,6 @@ ext { mavGitUrl = "https://github.com/jackpocket/android_scratchoff.git" mavScmConnection = "scm:git:git://github.com:jackpocket/android_scratchoff.git" mavScmDeveloperConnection = "scm:git:ssh://github.com:jackpocket/android_scratchoff.git" - - mavDeploymentRepo = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" - - mavenCentralUsername = localProperties.getProperty("mavenCentralUsername") - mavenCentralPassword = localProperties.getProperty("mavenCentralPassword") -} - -ext["signing.keyId"] = localProperties.getProperty("signing.keyId") -ext["signing.password"] = localProperties.getProperty("signing.password") -ext["signing.secretKeyRingFile"] = localProperties.getProperty("signing.secretKeyRingFile") - -task sourcesJar(type: Jar) { - archiveClassifier.set('sources') - from android.sourceSets.main.java.srcDirs -} - -task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - - android.libraryVariants.all { variant -> - if (variant.name == 'release') { - owner.classpath += variant.javaCompileProvider.get().classpath - } - } -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - archiveClassifier.set('javadoc') - from javadoc.destinationDir } afterEvaluate { @@ -71,9 +32,6 @@ afterEvaluate { release(MavenPublication) { from components.release - artifact sourcesJar - artifact javadocJar - groupId = mavPublishGroupId artifactId = mavProjectName version = mavLibraryVersion @@ -109,17 +67,23 @@ afterEvaluate { repositories { maven { name = 'mavenCentral' - url = mavDeploymentRepo + url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" credentials { - username mavenCentralUsername - password mavenCentralPassword + username "${System.getenv("MAVEN_CENTRAL_USER")}" + password "${System.getenv("MAVEN_CENTRAL_PASSWORD")}" } } } } signing { + useInMemoryPgpKeys( + System.getenv("RELEASE_SIGNING_KEY_ID"), + System.getenv("RELEASE_SIGNING_KEY"), + System.getenv("RELEASE_SIGNING_KEY_PASSWORD") + ) + sign publishing.publications } } \ No newline at end of file