Skip to content

Commit 1e99b68

Browse files
docs: how to create a GitHub Action (#1196)
<!-- 👋 Hi, thanks for sending a PR to create-typescript-app! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #1189 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview <!-- Description of what is changed and how the code change does that. --> This PR provides docs on how to create a GitHub Action --------- Co-authored-by: Josh Goldberg ✨ <[email protected]>
1 parent 8ccde11 commit 1e99b68

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"npmpackagejsonlintrc",
2525
"outro",
2626
"packagejson",
27+
"precommit",
2728
"quickstart",
2829
"tada",
2930
"tsup",

docs/FAQs.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,93 @@ After you set up a repository, you can substitute in any tools you'd like.
1313

1414
If you think the tool would be broadly useful to most consumers of this template, feel free to [file a feature request](https://github.com/JoshuaKGoldberg/create-typescript-app/issues/new?assignees=&labels=type%3A+feature&projects=&template=03-feature.yml&title=%F0%9F%9A%80+Feature%3A+%3Cshort+description+of+the+feature%3E) to add it in.
1515

16+
## Can I create a GitHub action?
17+
18+
Yes! If you want to read the [GitHub Actions documentation](https://docs.github.com/en/actions/creating-actions) in detail.
19+
Here we'll outline the steps required to migrate a CTA app to a GitHub Action:
20+
21+
1. GitHub Actions store built output on a GitHub branch rather than in a published package on npm.
22+
As a consequence we should:
23+
24+
- delete `.github/workflows/release.yml` and `.github/workflows/post-release.yml`.
25+
- update `.github/workflows/build.yml` to ensure `dist` is up to date:
26+
27+
<details>
28+
<summary><code>.github/workflows/build.yml</code></summary>
29+
30+
```yml
31+
jobs:
32+
build:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: ./.github/actions/prepare
37+
- run: pnpm build
38+
39+
- name: Compare dist/index.js
40+
run: |
41+
if [ "$(git diff --ignore-space-at-eol --text dist/index.js | wc -l)" -gt "0" ]; then
42+
echo "Detected uncommitted changes after build."
43+
echo "You may need to run 'pnpm run build' locally and commit the changes."
44+
echo ""
45+
echo "See diff below:"
46+
echo ""
47+
git diff --ignore-space-at-eol --text dist/index.js
48+
echo ""
49+
# say this again in case the diff is long
50+
echo "You may need to run 'pnpm run build' locally and commit the changes."
51+
echo ""
52+
exit 1
53+
fi
54+
55+
name: Build
56+
57+
on:
58+
pull_request: ~
59+
push:
60+
branches:
61+
- main
62+
63+
permissions:
64+
contents: read
65+
```
66+
67+
</details>
68+
69+
- GitHub Actions run without installing package dependencies.
70+
Replace `tsup` with [`ncc`](https://github.com/vercel/ncc) to build source files and dependencies into a single JS file.
71+
Delete `tsup.config.ts` then execute the following commands:
72+
73+
```bash
74+
pnpm remove tsup
75+
pnpm add @vercel/ncc -D
76+
```
77+
78+
- Now we need to update the `build` script in our `package.json`:
79+
80+
```diff
81+
-"build": "tsup",
82+
+"build": "ncc build src/index.ts -o dist --license licenses.txt",
83+
```
84+
85+
- Our build now emits to the `dist` directory; so we'll want to avoid linting that directory by adding the following to `.eslintignore` and our `.prettierignore`:
86+
87+
```diff
88+
+dist
89+
```
90+
91+
- Rather than having to remember to compile each time, we'll update our precommit hook in `.husky/precommit` to build for us on each commit:
92+
93+
```diff
94+
+pnpm run build
95+
+git add dist
96+
npx lint-staged
97+
```
98+
99+
2. Create an [`action.yml` metadata file](https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action#creating-an-action-metadata-file).
100+
101+
It's worth reading the [GitHub Actions documentation](https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action#writing-the-action-code).
102+
16103
## How can I add dual CommonJS / ECMAScript Modules emit?
17104

18105
First, I'd suggest reading [TypeScript Handbook > Modules - Introduction](https://www.typescriptlang.org/docs/handbook/modules/introduction.html) to understand how CommonJS (CJS) and ECMAScript (ESM) came to be.

script/__snapshots__/migrate-test-e2e.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ exports[`expected file changes > cspell.json 1`] = `
131131
"mtfoley",
132132
"npmignore",
133133
@@ ... @@
134-
"packagejson",
134+
"precommit",
135135
"quickstart",
136136
"tada",
137137
+ "templating",

0 commit comments

Comments
 (0)