GitHub Action Practice - Updating Workflow Version Badge

· 2 min read

I’ve written nearly 30 Alfred Workflows, and during usage, I iterate versions based on issues and shortcomings I encounter, then update them to GitHub for others to download and use. However, GitHub stores workflow file formats, making it impossible to directly see version information unless you download and install them. This makes it impossible to intuitively determine version issues.

Manual maintenance and updates? No, that’s too time-consuming.

Therefore, I need CI to help me read the workflow version and update it in the corresponding readme file, so I can quickly determine whether the locally installed version matches the repository-hosted version and whether an update is needed.

Feasibility Foundation

Alfred’s workflow files are essentially zip compressed files. After extraction, you’ll see a plist file that records version information.

Once feasibility is confirmed, it’s easy to proceed

Solution Design

Since I’m more proficient in JS, the key execution process is written in JavaScript. The overall solution is as follows:

  1. Monitor all workflow file changes, execute JS once there are changes
  2. Traverse all folders, get workflow files in the folders
  3. Copy files and rename with .zip suffix, execute decompression
  4. Read version information from plist file, replace original version info in readme file
  5. Commit updates to repository

Issues Encountered

There were still some pitfalls during implementation:

  1. Some workflow filenames contain spaces. If markdown links contain spaces, parsing will have issues, so transcoding needs to be done in advance. For transcoding, since it’s NodeJS, encodeURIComponent cannot be used, but queryString.escape can solve this.

  2. During local debugging, even though I installed plist to the global modules, the IDE still reported Module is not installed. It turns out that nodejs require for third-party modules doesn’t search in the global module folder, so you need to install to the project or use npm link plist

Final Thoughts

After setting up this mechanism, I only need to update the workflow in the repository in the future, and CI will automatically update the new version number to the readme. Nice!