Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/header-gen.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
name: Header Generator Tests

on:
release:
types: [created]
push:
branches: '*'
paths:
- "header-gen/**"
- "**/header-gen.yml"
pull_request:
branches: '*'
paths:
- "header-gen/**"
- "**/header-gen.yml"

jobs:
build-and-test:
name: Build & Test TS lib
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
Expand All @@ -18,15 +29,30 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: "https://npm.pkg.github.com"
cache: npm
cache-dependency-path: header-gen/package-lock.json

- name: Install Dependencies
run: npm ci
working-directory: ./header-gen

- name: Update version
if: github.event_name != 'pull_request'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step will also run on any pushes with changes to the header-gen source code, even if they are not meant to update the package version yet (which likely has already increased as we pxt bump the extension), is that the intention?

I assume this action only creates a commit if the version in package.json and the version in the last repo tag don't match?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the action should create a published version with something like @0.1.0-[branch_name].[build_number]. It should never create any commits.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But looking at the description in https://github.com/microbit-foundation/npm-package-versioner-action it sounds like if the package.json version entry needs to be updated it will do that? Does it do it without committing the change to the repo?

So, it changes package.json, builds package, pushes it to the package registry with a temporary tag like @0.1.0-[branch_name].[build_number] and doesn't commit anything? At what point it will push a package with the correct version number?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, the publishing is done by the npm publish step.

So, the microbit-foundation/npm-package-versioner-action action will change the package.json version entry if needed (maybe to 0.1.0-[branch_name].[build_number] as you mentioned), without committing anything and then it's up to other steps to create and/or publish the package. Is that right?

How does it decide if the version entry in package.json needs to be changed? is it if this commit is tagged AND the tag version is the same as the version in package.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies. This is ignorance on my part. We've not used this in prod yet and I naively assumed it would work in the same way as the package it's trying to replace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. It looks like it just changes the version in package.json without commiting anything. The udpated version number is only used for npm publish in that workflow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks Rob!

uses: microbit-foundation/npm-package-versioner-action@v1
with:
working-directory: ./header-gen

- name: Build
run: npm run build
working-directory: ./header-gen

- name: Run Jest Tests
run: npm test
working-directory: ./header-gen

- name: Publish
run: npm publish
if: github.event_name == 'release' && github.event.action == 'created'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions header-gen/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@microbit-foundation:registry=https://npm.pkg.github.com/microbit-foundation
8 changes: 4 additions & 4 deletions header-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "A simple TS script to generate a header blob for the ML runner",
"author": "Micro:bit Educational Foundation <package-help@microbit.org>",
"license": "MIT",
"module": "./dist/main.js",
"typings": "./dist/main.d.ts",
"module": "./built/main.js",
"typings": "./built/main.d.ts",
"files": [
"./dist/*.js",
"./dist/*.d.ts"
"./built/*.js",
"./built/*.d.ts"
],
"scripts": {
"start": "ts-node --project tsconfig.cli.json src/cli.ts",
Expand Down