2022-09-08 ● Gitlab CI Config to Neocities

I use GitLab’s CI pipelines to stage and deploy my changes over to Neocities. I used to use Neocel (a command line tool to deploy to Neocities) in my build scripts, but it’s not deploying my files correctly anymore so I’ve gone back to this build script. I want to outline the steps I took to remember what I did to get it working again, so this is a note to myself.

A code snippet of my build script in GitLab to Neocities.
[Image description: A code snippet of my build script in GitLab to Neocities. The snippet is available here.]

This is what my current build script looks like. I’ve split the job into two steps: build and deploy. I’m using Eleventy as my static site generator, and I first run a job to build the files to its output directory, _site (removing any possibly old files so that the build is clean).

After that, I run a job to deploy to Neocities. To do this, I had to first create a Gemfile in my site’s root directory that has these two lines:

source 'https://rubygems.org'

gem 'neocities'

I cd to that directory and run bundle install (sometimes the Gemfile is saved with a .rb extension, I had to manually remove it in order for it to be recognised by the bundler). This generates a Gemfile.lock file that must be committed to the repository.

Going back to the build script, I set the docker image to ruby:2.6.5 because the command line tool I’m using to deploy is Neocities’s CLI built on Ruby. I also need to specify the environment as neocities, and add a few steps it needs to do before it executes the deployment script.

First I need to create a file type variable in my site’s GitLab CI/CD settings using the API token I get via Neocities. (This can be found in the Site Settings of your Neocities account.)

A screenshot of the CI/CD variable settings in GitLab.
[Image description: A screenshot of the CI/CD variable settings in GitLab. More information from GitLab’s official docs.]

The type needs to be File, the key should be called NEOCITIES_TOKEN, and it should also be protected, masked, and scoped to the environment of neocities that I specified earlier.

Now I can go on to the deployment script which I copied from here. Essentially it checks if the NEOCITIES_TOKEN variable exists, and if it does, move it over to my Neocities config to be able to log into Neocities. I add additional commands to cd _site because that is the location of my files to be uploaded. Then I run the Ruby Neocities command to push everything in that directory to my Neocities account’s root directory.

Now each time I push to my main branch, this whole pipeline runs.

It took me ages (and one million broken pipelines later) to get this right because I didn’t read and follow instructions in a linear fashion. 🤧

Filed under: Changelog