Skip to content

Commit

Permalink
ci: oclif mess around (#1067)
Browse files Browse the repository at this point in the history
| 🚥 Resolves ISSUE_ID |
| :------------------- |

## 🧰 Changes

(still in-progress) separate PR from
[#1068](#1068) with a new
architecture for github actions that plays nicely with oclif.

outstanding work:
- [ ] remove all docker build/tagging/release code
- [ ] update `semantic-release` workflow to support this new process.
here are the assets we'll need to consider every time we tag a release
([link](https://github.com/readmeio/rdme/blob/d01d76fe3c2e4a98b4f5c415be03e589fbe3b56e/.releaserc.yml#L30)):
  - [ ] command list README (i.e., the one generated by `oclif readme`
- [ ] we do **not** need to update `action.yml` on every release anymore
- [ ] everything in `dist-gha` (the two JS files ~~and `package.json`~~)
- [ ] (do we need an `oclif` manifest in this directory? probably not?)
- [ ] we might not actually need to track this duplicated `package.json`
— what if we used the
[`runs.pre`](https://docs.github.com/en/actions/sharing-automations/creating-actions/metadata-syntax-for-github-actions#runspre)
script to generate it?
  - [ ] package/package-lock.json
  - [ ] CHANGELOG.md
- [ ] `oclif` manifest (this one is interesting... we probably don't
need to git track it but it should be included in our npm assets)

## 🧬 QA & Testing

Provide as much information as you can on how to test what you've done.
  • Loading branch information
kanadgupta authored Nov 18, 2024
1 parent 6f858aa commit b155c0e
Show file tree
Hide file tree
Showing 15 changed files with 401 additions and 813 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/
dist/
dist-gha/
exe/
15 changes: 4 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,10 @@ jobs:
path: oas-examples-repo
repository: readmeio/oas-examples

# For every GitHub Action release, we deploy our Docker images
# to the GitHub Container Registry for performance reasons.
# Instead of testing against the pre-built image, we can build
# an image from the currently checked-out repo contents by doing a
# li'l update in the action.yml file to point to the current Dockerfile.
- name: Replace Docker image value in action.yml
uses: jacobtomlinson/gha-find-replace@v3
with:
find: 'image:.*'
replace: "image: 'Dockerfile'"
include: rdme-repo/action.yml
# TODO: write a smol explainer comment
- name: Rebuild GitHub Action for testing purposes
run: 'npm ci && npm run build:gha'
working-directory: rdme-repo

- name: Run `openapi:validate` command
uses: ./rdme-repo/
Expand Down
14 changes: 3 additions & 11 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,9 @@ jobs:
regex: false
include: documentation/*

# For every GitHub Action release, we deploy our Docker images
# to the GitHub Container Registry for performance reasons.
# Instead of testing against the pre-built image, we can build
# an image from the currently checked-out repo contents by doing a
# li'l update in the action.yml file to point to the current Dockerfile.
- name: Replace Docker image value in action.yml
uses: jacobtomlinson/gha-find-replace@v3
with:
find: 'image:.*'
replace: "image: 'Dockerfile'"
include: action.yml
# TODO: write a smol explainer comment
- name: Rebuild GitHub Action for testing purposes
run: 'npm ci && npm run build:gha'

# And finally, with our updated documentation,
# we run the `rdme` GitHub Action to sync the Markdown file
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ node_modules/
tmp/

# required for building with TS
dist-gha/package.json
src/package.json
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ __tests__/__fixtures__/invalid-json/yikes.json
CHANGELOG.md
coverage/
dist/
dist-gha/
exe/
8 changes: 3 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ outputs:
rdme:
description: The rdme command result output
runs:
using: docker
image: docker://ghcr.io/readmeio/rdme:9.0.0-next.19
args:
- docker-gha
- ${{ inputs.rdme }}
using: node20
pre: bin/write-gha-pjson.js
main: dist-gha/run.cjs
8 changes: 7 additions & 1 deletion bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
// ^ we need this env variable above to hide the ExperimentalWarnings
// source: https://github.com/nodejs/node/issues/10802#issuecomment-573376999

import stringArgv from 'string-argv';

async function main() {
const { execute } = await import('@oclif/core');
await execute({ dir: import.meta.url }).then(msg => {
const opts = { dir: import.meta.url };
if (process.env.INPUT_RDME) {
opts.args = stringArgv(process.env.INPUT_RDME);
}
await execute(opts).then(msg => {
if (msg) {
// eslint-disable-next-line no-console
console.log(msg);
Expand Down
35 changes: 35 additions & 0 deletions bin/write-gha-pjson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /usr/bin/env node
// @ts-check

import fs from 'node:fs';
import path from 'node:path';

const newTarget = './cmds.js';

/**
* We need to duplicate the `package.json` file (with a few modifications) from the root of the project to the
* `dist-gha` directory, so that the GitHub Actions-flavored `oclif` configuration can find it.
*/
function writeGitHubActionsPackageJson() {
const current = JSON.parse(
fs.readFileSync(path.resolve(import.meta.dirname, '../package.json'), { encoding: 'utf-8' }),
);

current.private = true;

// set the correct targets for GitHub Actions
current.oclif.commands.target = newTarget;
Object.values(current.oclif.hooks).forEach(hook => {
// eslint-disable-next-line no-param-reassign
hook.target = newTarget;
});

// remove properties that are only applicable in a CLI context
delete current.oclif.helpClass;
delete current.oclif.plugins;

// write the new package.json file
fs.writeFileSync(path.resolve(import.meta.dirname, '../dist-gha/package.json'), JSON.stringify(current, null, 2));
}

writeGitHubActionsPackageJson();
93 changes: 93 additions & 0 deletions dist-gha/cmds.js

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions dist-gha/run.cjs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions knip.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { KnipConfig } from 'knip';

const config: KnipConfig = {
entry: ['src/index.ts', 'src/lib/help.ts'],
ignore: ['bin/*.js'],
entry: ['src/index.ts', 'src/lib/help.ts', 'bin/*.js'],
ignore: ['dist-gha/**'],
ignoreBinaries: ['semantic-release'],
ignoreDependencies: ['oclif'],
};
Expand Down
Loading

0 comments on commit b155c0e

Please sign in to comment.