301 Days

A year of gamedev experiments.

Day 78b - Cop Replacement

| Comments

In which we do some automated policing.

Improve the Blog Every Third Day

I did a bunch of work on the new version of the blog (Jekyll 3, clean dark theme), converting all but the middle thirty posts; but more importantly, I did some long-overdue automation of the process using RegReplace.

It took a little bit of doing, but the sequence of heavily regex’d find-and-replace tasks are now a single Sublime command.

reg_replace_rules.sublime-settings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{
  "format": "3.0",
  "replacements":
  {
      "octo_to_jekyll_backtick_codeblock":
      {
          "find": "``` *([\\S]+) *([^\\n]*)\\n([\\s\\S]+?)```",
          "replace": "{\% codeblock lang:\\1 \\2 %}\\n\\3{\% endcodeblock %}"
      },
      "octo_to_jekyll_backtick_newline":
      {
          "find": "\\n+```([\\S\\s]+?)```",
          "replace": "\\n\\n```\\1```"
      },
        "octo_to_jekyll_backtick_plain":
        {
            "find": "\\n```\\s*\\n([\\S\\s]+?)```",
            "replace": "\\n``` plain\\n\\1```"
        },
      "octo_to_jekyll_center_img":
      {
          "find": "{\% center left ([\\S]+)\\s([^%]*) %}",
          "replace": "![\\2](\\1 \"\\2\"){: .center-image }"
      },
      "octo_to_jekyll_noncenter_img":
      {
          "find": "{\% img left ([\\S]+)\\s([^%]*) %}",
          "replace": "![\\2](\\1 \"\\2\")"
      },
      "octo_to_jekyll_heading_newline":
      {
          "find": "\\*\\*\\*\\n\\#",
          "replace": "***\\n\\n#"
      },
      "octo_to_jekyll_single_cat":
      {
          "find": "\\ncategories:\\s*\\[\\s*([^,^\\]]+?)\\s*\\]",
          "replace": "\\ntags:\\n - \\1"
      },
      "octo_to_jekyll_two_cat":
      {
          "find": "\\ncategories:\\s*\\[\\s*([^,^\\]]+?),\\s*([^,^\\]]+?)\\s*\\]",
          "replace": "\\ntags:\\n - \\1\\n - \\2"
      },
      "remove_trailing_spaces":
      {
          "find": "[ \\t]+$",
          "replace": ""
      }
  }
}

(Note: The percent sign is only escaped here to keep Jekyll from processing it.)

Default.sublime-commands
1
2
3
4
5
6
7
8
9
10
    {
        "caption": "Reg Replace: Convert Octopress 2 blog post to Jekyll3 custom",
        "command": "reg_replace",
        "args": {"replacements": ["remove_trailing_spaces", "octo_to_jekyll_center_img",
            "octo_to_jekyll_center_img",
            "octo_to_jekyll_single_cat", "octo_to_jekyll_two_cat",
            "octo_to_jekyll_backtick_codeblock", "octo_to_jekyll_backtick_newline",
            "octo_to_jekyll_backtick_plain",
            "octo_to_jekyll_heading_newline", "remove_trailing_spaces"]}
    },

Now I’m comfortable to say I can do the switch-over in the next week or so.

Throw it in the Cloud Every Thirteenth Day

One of the overdue items on this project is some sort of continuous integration. It’ll be awkward with the legacy Windows server, but probably worth it. For now, though, let’s just get the ball rolling with some test code linting.

GitLab CI

I’ve used Travis CI quite a bit professionally, but since we’re on GitLab for this, I thought I’d give their new CI offerings a try. I created a .gitlab-ci.yml based on their example code:

https://gitlab.com/LiBiPlJoe/seitan-spin/blob/9c444b9ac4faff9f2d698e3b2351d6c26900034e/.gitlab-ci.ymllink
1
2
3
4
5
6
7
8
9
10
before_script:
  - apt-get update -qq
  - ruby -v
  - which ruby
  - gem install bundler --no-ri --no-rdoc
  - bundle install --jobs $(nproc)  "${FLAGS[@]}"
rubocop:
  script:
    - bundle exec rubocop
    - echo 'Hello, World!'

I pushed it up, and… nothing. No errors, but no building. Experimented on some other repositories, and it was just this one that was ignoring my CI config. After a lot of poking around, I found the problem:

Project Settings -> Feature Visibility -> Repository -> Builds was set to Disabled, which I must have thought was a good idea at some point. Once I made it anything else, Rubocop was run as expected.

Rubocop

I had been writing a bunch of code in a general-purpose editor, without ever running it through a linter, so the results are not unexpected:

1
2
30 files inspected, 1031 offenses detected
ERROR: Build failed: exit code 1

And this is after I made a configuration change:

https://gitlab.com/LiBiPlJoe/seitan-spin/blob/master/.rubocop.ymllink
2
3
Metrics/LineLength:
  Max: 100

As nostalgic as I sometimes am for “the good old days”, I feel terribly constrained by eighty-character lines. One hundred seemed a nice round number, so I’ve settled on that.

Well, Rubocop’s certainly given us plenty of work to do. Tomorrow.


Useful Stuff


Day 78b code - tests

Comments