Skip to content

Commit

Permalink
Add automated release workflow
Browse files Browse the repository at this point in the history
Mostly cribbed from rewrite-clj.

Currently invoked from GitHub Actions UI.

Version scheme is major.minor.<release count>.

See new maintainer guide for details.

Closes clj-commons#422
  • Loading branch information
lread committed Aug 2, 2022
1 parent d45c2c8 commit 5b30480
Show file tree
Hide file tree
Showing 8 changed files with 389 additions and 23 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Release
on:
workflow_dispatch:

jobs:
release:
environment: release

runs-on: ubuntu-latest
# I do not know of a way to restrict to the main branch so try to skip the whole job if
# user selected some other branch from GitHub Actions GUI
if: github.ref == 'refs/heads/main'

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Git User so that we can later commit
uses: fregante/setup-git-user@v1

- name: Clojure deps cache
uses: actions/cache@v3
with:
path: |
~/.m2/repository
~/.deps.clj
~/.gitlibs
key: cljdeps-${{ hashFiles('deps.edn', 'bb.edn') }}
restore-keys: cljdeps-

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'

- name: Install Clojure Tools
uses: DeLaGuardo/[email protected]
with:
bb: 'latest'

- name: Tools Versions
run: |
echo "bb --version"
bb --version
echo "java -version"
java -version
- name: Download Clojure Dependencies
run: bb download-deps

- name: Release Prep (step 1 of 4)
run: bb ci-release prep

- name: Release Deploy (step 2 of 4)
env:
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }}
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
run: bb ci-release deploy-remote

- name: Release Commit (step 3 of 4)
run: bb ci-release commit

- name: Make GitHub Actions aware of target version tag
run: echo "::set-output name=tag::v$(bb clojure -T:build built-version)"
id: target-version

- name: Create GitHub release (step 4 of 4)
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.target-version.outputs.tag}}
release_name: ${{ steps.target-version.outputs.tag}}
commitish: main
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Fixed.
** https://github.com/clj-commons/etaoin/issues/391[#391]: Identify browser name on failed ide tests
** https://github.com/clj-commons/etaoin/issues/390[#390]: Add internal clj-kondo config
** https://github.com/clj-commons/etaoin/issues/381[#381]: In addition to ubuntu, now also testing on macOS and Windows (using GitHub Actions https://github.com/clj-commons/etaoin/issues/392[#392] with parallelization https://github.com/clj-commons/etaoin/issues/420[#420])
** https://github.com/clj-commons/etaoin/issues/422[#422]: Automate release workflow

== v0.4.6

Expand Down
6 changes: 4 additions & 2 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{:min-bb-version "0.8.2"
:paths ["script"]
:paths ["script" "build"]
:deps {doric/doric {:mvn/version "0.9.0"}
lread/status-line {:git/url "https://github.com/lread/status-line.git"
:sha "35ed39645038e81b42cb15ed6753b8462e60a06d"}
Expand Down Expand Up @@ -52,4 +52,6 @@
(str (fs/cwd) ":/etaoin")
"-w" "/etaoin"
"etaoin:latest"
*command-line-args*)}}}
*command-line-args*)}
ci-release {:doc "release tasks, use --help for args"
:task ci-release/-main }}}
53 changes: 33 additions & 20 deletions build.clj
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
(ns build
(:require [clojure.tools.build.api :as b]
[clojure.string :as string]))
(:require [clojure.edn :as edn]
[clojure.java.io :as io]
[clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]))

(defn- num-releases
"We'll assume num tags = num releases"
[]
(-> (b/git-process {:git-args "tags"})
(string/split-lines)
count))
(defn version-string []
(let [{:keys [major minor release qualifier]} (-> "version.edn"
slurp
edn/read-string)]
(format "%s.%s.%s%s"
major minor release (if qualifier
(str "-" qualifier)
""))))

(def lib 'etaoin/etaoin)
(def version (format "1.0.%d" (inc (num-releases))))
(def version (version-string)) ;; the expectations is some pre-processing has bumped the version when releasing
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def jar-file (format "target/%s-%s.jar" (name lib) version))
(def jar-file (format "target/%s.jar" (name lib)))
(def built-jar-version-file "target/built-jar-version.txt")

(defn clean [_]
Expand All @@ -29,11 +33,10 @@
(let [version (if version-suffix
(format "%s-%s" version version-suffix)
version)]

(b/write-pom {:class-dir class-dir
:lib lib
:version version
:scm {:tag version}
:scm {:tag (format "v%s" version)}
:basis basis
:src-dirs ["src"]})
(b/copy-dir {:src-dirs ["src" "resources"]
Expand All @@ -43,6 +46,19 @@
(spit built-jar-version-file version)
(assoc opts :built-jar-version version)))

(defn- built-version* []
(when (not (.exists (io/file built-jar-version-file)))
(throw (ex-info (str "Built jar version file not found: " built-jar-version-file) {})))
(slurp built-jar-version-file))

(defn built-version
;; NOTE: Used by release script and github workflow
"Spit out version of jar built (with no trailing newline).
A separate task because I don't know what build.tools might spit to stdout."
[_]
(print (built-version*))
(flush))

(defn install [opts]
(clean opts)
(let [{:keys [built-jar-version]} (jar opts)]
Expand All @@ -52,12 +68,9 @@
:basis basis
:jar-file jar-file})))

(defn publish [opts]
(clean opts)
(jar opts)
((requiring-resolve 'deps-deploy.deps-deploy/deploy)
(merge {:installer :remote
:artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})}
opts))
(defn deploy [opts]
(dd/deploy
{:installer :remote
:artifact jar-file
:pom-file (b/pom-path {:lib lib :class-dir class-dir})})
opts)
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

:build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.3" :git/sha "0d20256"}
slipset/deps-deploy {:mvn/version "0.2.0"}}
:extra-paths ["build"]
:ns-default build}

:outdated {:extra-deps {com.github.liquidz/antq {:mvn/version "1.9.874"}
Expand Down
62 changes: 61 additions & 1 deletion doc/03-maintainer-guide.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,66 @@
= Maintainer Guide
:toclevels: 5
:toc:
:url-release-action: https://github.com/clj-commons/etaoin/actions?query=workflow%3A%22Release%22

== Introduction
Coming soon
Notes for project maintainers.

== Release Workflow

The release workflow is handled by our link:{url-release-action}[Release] GitHub Action.

. Fail fast if:
.. Change log not ready
. Bump `version.edn` for release version
. Create thin jar using release version
. Apply release version to the following docs:
.. user guide for usage examples
.. change log "unreleased" heading
. Deploy jar to clojars
. Commit changes made to docs and `version.edn`
. Create and push a release tag back to the project repo
. Inform cljdoc of the new release

[IMPORTANT]
====
At this time, the release workflow does not run tests.
The assumption is that you've waited for the last CI test run to complete and are happy with the results.
====

== Updating the Version

Release num is bumped automatically by release workflow.

Edit `major` and `minor` by editing `version.edn` in the project root.

== Local Verification

To check if things seeem ready:

[source,shell]
----
bb ci-release validate
----

If you want to run everything up to, but not including, commit and push:

[source,shell]
----
bb ci-release prep
----

IMPORTANT: You will NOT want to check in changes made by `prep`.

== Special Setup

GitHub has been configured with necessary secrets for GitHub Actions to deploy to clojars.

== Invoking

As a maintainer you should have sufficient privileges to see a "Run Workflow" dropdown button on the link:{url-release-action}[Release] action page.
The dropdown will prompt for a branch.
I did not see a way to disable this prompt, simply leave it at "master" and run the workflow.

TIP: Don't forget to pull after a release to get the changes made by the release workflow.

Loading

0 comments on commit 5b30480

Please sign in to comment.