From a0e76c8614ad882687685f790948edd57f505d1e Mon Sep 17 00:00:00 2001 From: AJ Date: Wed, 6 Mar 2024 10:22:30 -0800 Subject: [PATCH] Add release workflow --- .github/workflows/build.yml | 4 +- .github/workflows/release.yml | 45 +++++++++++++++++++ .../mordant-publishing-conventions.gradle.kts | 13 +----- deploy_website.sh => prepare_docs.sh | 20 +++------ 4 files changed, 56 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/release.yml rename deploy_website.sh => prepare_docs.sh (56%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f28260240..911415ca8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: java-version: 17 distribution: 'graalvm-community' set-java-home: false - - uses: actions/setup-java@v3 + - uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: 17 @@ -60,7 +60,7 @@ jobs: - uses: actions/checkout@v4 - name: Fetch git tags run: git fetch origin +refs/tags/*:refs/tags/* - - uses: actions/setup-java@v3 + - uses: actions/setup-java@v4 with: distribution: 'zulu' java-version: 17 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..5c654053d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: release + +on: + push: + tags: + - '**' + +jobs: + release: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: 17 + - uses: actions/setup-python@v5 + with: + python-version: '3.12' + - run: ./gradlew publishToMavenCentral + env: + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralPassword }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKey }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralUsername }} + - name: Extract release notes + id: extract-release-notes + uses: ffurrer2/extract-release-notes@v2 + - name: Create release + uses: ncipollo/release-action@v1 + with: + body: ${{ steps.extract-release-notes.outputs.release_notes }} + - name: Dokka + uses: gradle/actions/setup-gradle@v3 + with: + arguments: dokkaHtmlMultiModule + - run : ./prepare_docs.sh + - name: Build mkdocs + run: | + pip install mkdocs-material + mkdocs build + - name: Deploy docs to website + uses: JamesIves/github-pages-deploy-action@v4 + with: + branch: gh-pages + folder: site diff --git a/buildSrc/src/main/kotlin/mordant-publishing-conventions.gradle.kts b/buildSrc/src/main/kotlin/mordant-publishing-conventions.gradle.kts index edce6bb1a..5c8e7d32d 100644 --- a/buildSrc/src/main/kotlin/mordant-publishing-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/mordant-publishing-conventions.gradle.kts @@ -13,18 +13,9 @@ plugins { fun getPublishVersion(): String { val version = project.property("VERSION_NAME").toString() - // Call gradle with -PinferVersion to set the dynamic version name. + // Call gradle with -PsnapshotVersion to set the version as a snapshot. // Otherwise, we skip it to save time. - if (!project.hasProperty("inferVersion")) return version - - val stdout = ByteArrayOutputStream() - project.exec { - commandLine = listOf("git", "tag", "--points-at", "master") - standardOutput = stdout - } - val tag = String(stdout.toByteArray()).trim() - if (tag.isNotEmpty()) return tag - + if (!project.hasProperty("snapshotVersion")) return version val buildNumber = System.getenv("GITHUB_RUN_NUMBER") ?: "0" return "$version.$buildNumber-SNAPSHOT" } diff --git a/deploy_website.sh b/prepare_docs.sh similarity index 56% rename from deploy_website.sh rename to prepare_docs.sh index 41a098895..84fe451bc 100755 --- a/deploy_website.sh +++ b/prepare_docs.sh @@ -2,15 +2,14 @@ # The website is built using MkDocs with the Material theme. # https://squidfunk.github.io/mkdocs-material/ -# It requires Python to run. -# Install the packages with the following command: -# pip install mkdocs mkdocs-material +# Mkdocs requires Python to run. +# Install the packages: `pip install mkdocs-material` +# Build the api docs: `./gradlew dokkaHtmlMultiModule` +# Then run this script to prepare the docs for the website. +# Finally, run `mkdocs serve` to preview the site locally or `mkdocs build` to build the site. set -ex -# Generate API docs -./gradlew dokkaHtmlMultiModule - # Copy the changelog into the site, omitting the unreleased section cat CHANGELOG.md \ | grep -v '^## Unreleased' \ @@ -26,15 +25,10 @@ hide: EOM -# Copy the README into the index, omitting the license and fixing hrefs +# Copy the README into the index, omitting the docs link, license and fixing hrefs cat README.md \ | sed '/## License/Q' \ + | sed -z 's/## Documentation[a-zA-z .\n()/:]*//g' \ | sed 's!https://ajalt.github.io/mordant/!/!g' \ | sed 's!docs/img!img!g' \ >> docs/index.md - -# Build and deploy the new site to github pages -mkdocs gh-deploy - -# Remove the file copies -rm docs/index.md docs/changelog.md