Theme development in CI/CD fashion

Hi,
do you guys have suggestion how to approach theme deployment in CI/CD fashion? Client expects new theme releases every two weeks and we would like to ship theme in automated process. We are using discourse docker.

We would like to avoid manual installation for each release.

Side note, I don’t know if this is a bug, but the it seems branch doesn’t get saved on first theme installation. (Need to double check this to confirm)

Thanks

2 Likes

Its already there. If you install a theme via a git repo, you can update the theme to the latest commit in a single click.

I know that, but that’s not the way we want to do it.

We want to have dynamic process without touching the discourse admin. I was thinking using themes command https://github.com/discourse/discourse/blob/master/lib/tasks/themes.rake

docker exec -it app rails themes:install -- # theme data

I don’t know if this command can read files. For example - theme.yaml file which would contain theme info for instalation.
That file could be deployed to shared folder and docker command could read it from there and install the theme or make updates.

@markvanlan recently did some work which might be useful for you

https://github.com/discourse/discourse/commit/f07c4a781c6c054e5d2dc05ab6c0fd0b6cbb0645

There is some usage info in the comments here:
https://github.com/discourse/discourse/blob/f07c4a781c6c054e5d2dc05ab6c0fd0b6cbb0645/lib/tasks/themes.rake#L5-L26

8 Likes

@david thanks, but it doesn’t seem clear to me if I can put path to file as an argument. Would this work?

bin/rake themes:install -- theme.yaml 

Maybe I could try.

I think you would pipe it to STDIN, so something like

cat theme_config.yml | bin/rake themes:install

But I haven’t tested that. Let us know if it works for you :slight_smile:

6 Likes

Your approach works fine. Thanks! Mine doesn’t. :smiley:

I did experiment a bit with modifying themes.rake by adding

rake themes:install themeFile="theme.yml"

And this:

task "themes:install" => :environment do |task, args|
  if ENV['themeFile']
    theme_args = YAML.load_file(ENV['themeFile'])
  else
    theme_args = (STDIN.tty?) ? '' : STDIN.read
    use_json = theme_args == ''
    theme_args =
      begin
        use_json ? JSON.parse(ARGV.last.gsub('--', '')) : YAML::load(theme_args)
      rescue
        puts use_json ? "Invalid JSON input. \n#{ARGV.last}" : "Invalid YML: \n#{theme_args}"
        exit 1
      end
    end

  log, counts = ThemesInstallTask.install(theme_args)

  puts log

  puts
  puts "Results:"
  puts " Installed: #{counts[:installed]}"
  puts " Updated:   #{counts[:updated]}"
  puts " Errors:    #{counts[:errors]}"

  if counts[:errors] > 0
    exit 1
  end
end

Works fine. :sweat_smile:

How to run spec for this file?

1 Like

You should be able to do this:

bin/rake themes:install theme.yml

I added support for passing in JSON, but this code was originally designed to take a yml file as the argument.

2 Likes

It throws that it’s not valid json

Invalid JSON input.
theme.yml

My theme.yml

test:
  url: "https://github.com/discourse/discourse-faria-theme"
2 Likes

I believe that should work! I will look into why it is not working anymore.

2 Likes

Alright, the proper format is bin/rake themes:install < theme.yml. I will document this better in the code :slight_smile:

15 Likes

Nice! Thanks! Glad I could help a bit :sweat_smile:

4 Likes