Search code examples
clojureyamlgithub-actionsworkflowcontinuous-deployment

How to run GitHub Actions workflow only if the pushed changes are in a specific *line* of a specific file?


I have been using Clojure, ClojureScript, lein, shadow-cljs, re-frame, reagent, Emacs, and CIDER to work on a Clojure/ClojureScript dynamic web app project.

Now, I am trying to make dependencies become private Maven packages hosted for free on GitHub packages. I already managed to publish some package!

Right now, I have on my .yml file:

on:
  workflow_dispatch:
  push:
    branches:
      - main
    paths:
      - 'project.clj'
  pull_request:
    paths:
      - 'project.clj'

If my understanding is correct, this means that the GitHub workflows only runs after Pull Requests on tweaking file project.clj and direct changes on main branch tweaking project.clj.

This is close to what I need!

Context: I am building this to publish Maven packages as GitHub packages. As clojure folks might know, usually, the version of the project is "hard code-documented" on the first line of project.clj file. Hence, I want to publish a new package every time this library gets a new version.

For instance, the first line has:

(defproject my-repository "0.6.50-RELEASE-TEST-9-via-GitHub-Actions-CD"

At some point, it will be changed to:

(defproject my-repository "0.6.51"

I would like to adjust the GitHub Actions script so that it only runs for changes on this file project.clj and on the first line!

Is this possible?


Solution

  • If you try really hard enough, you can pull it off, but there's a simpler way:

    You can read contents of a file and set that as a version of your library:

    (defproject foobar (clojure.string/trim (slurp "./VERSION"))
    

    then in your workflow, you don't watch for changes to project.clj but the VERSION file only, that you can update using a script or whatever you need.