gitlabgitlab-cisemantic-release

using semantic-release to update version strings in release and via commit for non-npm project


I am developing a handful of WordPress projects on Gitlab and I would like to use semantic-release to automatically manage releases. To that end I'm trying to accomplish a few additional things:

I'm pretty sure I'm close, I've got the first item (via google's semantic-release-replace-plugin) but not the second. Up to this point I've tried to do most things via semantic-releases' plugin ecosystem, but if need be I can venture into script territory.

My .releaserc looks like:

{
  "branches": [ "main" ],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    [
      "@google/semantic-release-replace-plugin",
      {
        "replacements": [
          {
            "files": ["style.css"],
            "from": "Version: .*",
            "to": "Version: ${nextRelease.version}",
            "results": [
              {
                "file": "style.css",
                "hasChanged": true,
                "numMatches": 1,
                "numReplacements": 1
              }
            ],
            "countMatches": true
          }
        ]
      }
    ],
    [
      "@semantic-release/git",
      {
        "assets": ["style.css"]
      }
    ],
    [
      "@semantic-release/gitlab", 
      {
        "assets": [
          {"path": "experiments.zip", "label": "zip"}
        ]
      }
    ]
  ]
}

And the .gitlab-ci.yml looks like:

variables:
  GL_TOKEN: $GL_TOKEN

stages:
    - release

before_script:
  - npm install

publish:
  image: cimg/php:7.4-node
  stage: release
  script:
    - npm run build
    - npm run zip
    - npx semantic-release
  only:
    refs:
      - main

Where npm run build compiles some assets and npm run zip is a JavaScript-based script that zips up the desired production-ready files, in this case to generate the experiments.zip.

Any suggestions would be appreciated!


Solution

  • So the main issue here was that compilation was just not occurring at the right time and I needed to slip a

    "@semantic-release/exec",
    {
        "prepareCmd": "node bin/makezip.js"
    }
    

    between "@semantic-release/git" and "@semantic-release/gitlab".