├── .github
└── workflows
│ ├── actionlint.yml
│ └── is-dist-up-to-date.yml
├── .gitignore
├── action-release
└── action-release.yml
├── esm-lint
└── esm-lint.yml
├── is-dist-up-to-date
└── is-dist-up-to-date.yml
├── license
├── node-multi
└── ci.yml
├── node
└── ci.yml
├── npm-publish
└── npm-publish.yml
├── package.json
├── readme.md
└── webext
└── release.yml
/.github/workflows/actionlint.yml:
--------------------------------------------------------------------------------
1 | # Copied from https://github.com/rhysd/actionlint/blob/048c97d90b98b832450d3adf00fc7757b0ed9953/docs/usage.md#use-actionlint-on-github-actions
2 | name: actionlint
3 | on: [push, pull_request]
4 |
5 | jobs:
6 | actionlint:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v4
10 | - uses: raven-actions/actionlint@v1
11 |
--------------------------------------------------------------------------------
/.github/workflows/is-dist-up-to-date.yml:
--------------------------------------------------------------------------------
1 | env:
2 | SCRIPT_NAME: format
3 |
4 | # FILE GENERATED WITH: npx ghat fregante/ghatemplates/is-dist-up-to-date
5 | # SOURCE: https://github.com/fregante/ghatemplates
6 |
7 | name: Verify Built Files
8 | on:
9 | - pull_request
10 | - push
11 | jobs:
12 | Verify:
13 | runs-on: ubuntu-latest
14 | steps:
15 | - uses: actions/checkout@v4
16 | - name: install
17 | run: npm ci || npm install
18 | - run: npm run ${{ env.SCRIPT_NAME }}
19 | - name: verify that built files are up to date
20 | run: git diff --exit-code
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | package-lock.json
2 |
--------------------------------------------------------------------------------
/action-release/action-release.yml:
--------------------------------------------------------------------------------
1 | name: Release
2 |
3 | on:
4 | workflow_dispatch:
5 | # You can manually trigger a deployment on GitHub.com
6 | # https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
7 | inputs:
8 | Version:
9 | description: 'Example: v1.2.3'
10 | required: true
11 |
12 | jobs:
13 | Release:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@v4
17 | - run: gh release create ${{ github.event.inputs.Version }} --generate-notes
18 | env:
19 | GH_TOKEN: ${{ github.token }}
20 | - name: Update major tag
21 | run: |
22 | MAJOR=$(echo ${{ github.event.inputs.Version }} | sed 's/\..*//')
23 | git push origin HEAD:refs/tags/$MAJOR --force
24 |
--------------------------------------------------------------------------------
/esm-lint/esm-lint.yml:
--------------------------------------------------------------------------------
1 | name: ESM
2 |
3 | env:
4 | IMPORT_STATEMENT: import YourModuleHere from "your-module-here"
5 |
6 | on:
7 | pull_request:
8 | branches:
9 | - '*'
10 | push:
11 | branches:
12 | - master
13 | - main
14 |
15 | jobs:
16 | Pack:
17 | runs-on: ubuntu-latest
18 | steps:
19 | - uses: actions/checkout@v4
20 | - run: npm install
21 | - run: npm run build --if-present
22 | - run: npm pack --dry-run
23 | - run: npm pack | tail -1 | xargs -n1 tar -xzf
24 | - uses: actions/upload-artifact@v4
25 | with:
26 | path: package
27 |
28 | Publint:
29 | runs-on: ubuntu-latest
30 | needs: Pack
31 | steps:
32 | - uses: actions/download-artifact@v4
33 | - run: npx publint ./artifact
34 |
35 | Webpack:
36 | runs-on: ubuntu-latest
37 | needs: Pack
38 | steps:
39 | - uses: actions/download-artifact@v4
40 | - run: npm install --omit=dev ./artifact
41 | - run: echo "$IMPORT_STATEMENT" > index.js
42 | - run: webpack --entry ./index.js
43 | - run: cat dist/main.js
44 |
45 | Parcel:
46 | runs-on: ubuntu-latest
47 | needs: Pack
48 | steps:
49 | - uses: actions/download-artifact@v4
50 | - run: npm install --omit=dev ./artifact
51 | - run: echo "$IMPORT_STATEMENT" > index.js
52 | - run: |
53 | echo '{"@parcel/resolver-default": {"packageExports": true}}' > package.json
54 | - run: npx parcel@2 build index.js
55 | - run: cat dist/index.js
56 |
57 | Rollup:
58 | runs-on: ubuntu-latest
59 | needs: Pack
60 | steps:
61 | - uses: actions/download-artifact@v4
62 | - run: npm install --omit=dev ./artifact rollup@4 @rollup/plugin-node-resolve
63 | - run: echo "$IMPORT_STATEMENT" > index.js
64 | - run: npx rollup -p node-resolve index.js
65 |
66 | Vite:
67 | runs-on: ubuntu-latest
68 | needs: Pack
69 | steps:
70 | - uses: actions/download-artifact@v4
71 | - run: npm install --omit=dev ./artifact
72 | - run: echo '' > index.html
73 | - run: npx vite build
74 | - run: cat dist/assets/*
75 |
76 | esbuild:
77 | runs-on: ubuntu-latest
78 | needs: Pack
79 | steps:
80 | - uses: actions/download-artifact@v4
81 | - run: echo '{}' > package.json
82 | - run: echo "$IMPORT_STATEMENT" > index.js
83 | - run: npm install --omit=dev ./artifact
84 | - run: npx esbuild --bundle index.js
85 |
86 | TypeScript:
87 | runs-on: ubuntu-latest
88 | needs: Pack
89 | steps:
90 | - uses: actions/download-artifact@v4
91 | - run: echo '{"type":"module"}' > package.json
92 | - run: npm install --omit=dev ./artifact @sindresorhus/tsconfig
93 | - run: echo "$IMPORT_STATEMENT" > index.mts
94 | - run: >
95 | echo '{"extends":"@sindresorhus/tsconfig","files":["index.mts"]}' >
96 | tsconfig.json
97 | - run: npx --package typescript -- tsc
98 | - run: cat distribution/index.mjs
99 |
100 | Node:
101 | runs-on: ubuntu-latest
102 | needs: Pack
103 | steps:
104 | - uses: actions/download-artifact@v4
105 | - uses: actions/setup-node@v4
106 | with:
107 | node-version-file: artifact/package.json
108 | - run: echo "$IMPORT_STATEMENT" > index.mjs
109 | - run: npm install --omit=dev ./artifact
110 | - run: node index.mjs
111 |
--------------------------------------------------------------------------------
/is-dist-up-to-date/is-dist-up-to-date.yml:
--------------------------------------------------------------------------------
1 | name: Verify Built Files
2 |
3 | on:
4 | - pull_request
5 | - push
6 |
7 | env:
8 | SCRIPT_NAME: build
9 |
10 | jobs:
11 | Verify:
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v4
15 | - name: install
16 | run: npm ci || npm install
17 | - run: npm run ${{ env.SCRIPT_NAME }}
18 | - name: verify that built files are up to date
19 | run: git diff --exit-code
20 |
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Federico Brigante (https://fregante.com)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10 |
--------------------------------------------------------------------------------
/node-multi/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on:
3 | - push
4 | - pull_request
5 | jobs:
6 | test:
7 | name: Node.js ${{ matrix.node-version }}
8 | runs-on: ubuntu-latest
9 | strategy:
10 | fail-fast: false
11 | matrix:
12 | node-version:
13 | - 14
14 | - 12
15 | steps:
16 | - uses: actions/checkout@v4
17 | - uses: actions/setup-node@v4
18 | with:
19 | node-version: ${{ matrix.node-version }}
20 | - run: npm ci || npm install
21 | - run: npm test
22 |
--------------------------------------------------------------------------------
/node/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | - pull_request
5 | - push
6 |
7 | jobs:
8 | Lint:
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: actions/checkout@v4
12 | - uses: actions/setup-node@v4
13 | with:
14 | node-version-file: package.json
15 | cache: npm
16 | - name: install
17 | run: npm ci || npm install
18 | - name: XO
19 | run: npx xo
20 |
21 | Test:
22 | runs-on: ubuntu-latest
23 | steps:
24 | - uses: actions/checkout@v4
25 | - uses: actions/setup-node@v4
26 | with:
27 | node-version-file: package.json
28 | cache: npm
29 | - name: install
30 | run: npm ci || npm install
31 | - name: build
32 | run: npm run build --if-present
33 | - name: AVA
34 | run: npx ava
35 |
36 | Build:
37 | runs-on: ubuntu-latest
38 | steps:
39 | - uses: actions/checkout@v4
40 | - uses: actions/setup-node@v4
41 | with:
42 | node-version-file: package.json
43 | cache: npm
44 | - name: install
45 | run: npm ci || npm install
46 | - name: build
47 | run: npm run build
48 |
--------------------------------------------------------------------------------
/npm-publish/npm-publish.yml:
--------------------------------------------------------------------------------
1 | # Collaborators can publish a new version of what's on master via "workflow_dispatch"
2 | # https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
3 |
4 | name: Publish
5 |
6 | on:
7 | workflow_dispatch:
8 | inputs:
9 | Version:
10 | description: 'Version accepted by `npm version *`'
11 | required: true
12 |
13 | jobs:
14 | NPM:
15 | runs-on: ubuntu-latest
16 | steps:
17 | - uses: actions/checkout@v4
18 | - uses: actions/setup-node@v4
19 | with:
20 | node-version-file: package.json
21 | registry-url: https://registry.npmjs.org
22 | - run: npm ci || npm install
23 | - uses: fregante/setup-git-user@v2
24 | - run: npm version "${{ github.event.inputs.Version }}"
25 | - run: npm publish
26 | env:
27 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
28 | - run: git push --follow-tags
29 | # `git tag` enables support for keywords: `npm version patch`
30 | - run: gh release create "$(git tag --points-at HEAD)" --generate-notes
31 | env:
32 | GH_TOKEN: ${{ github.token }}
33 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "format": "npx prettier@3 --write --use-tabs --single-quote ."
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # GH Actions Templates
2 |
3 | Use [ghat](https://github.com/fregante/ghat) to easily share your workflows or copy the workflows shared in this repository.
4 |
5 | ## [webext/release.yml](./webext/release.yml)
6 |
7 | ```sh
8 | npx ghat fregante/ghatemplates/webext/release.yml
9 | ```
10 |
11 | And then remember to choose a random `cronjob` value.
12 |
13 | Used by:
14 |
15 | - https://github.com/sindresorhus/refined-github
16 | - https://github.com/npmhub/npmhub
17 |
18 | ## [esm-lint](./esm-lint/esm-lint.yml)
19 |
20 | Package/ESM compatibility linter, details in https://github.com/sindresorhus/project-ideas/issues/116
21 |
22 | ```sh
23 | npx ghat fregante/ghatemplates/esm-lint
24 | ```
25 |
26 | You can also exclude some tests irrelevant to your project:
27 |
28 | ```sh
29 | npx ghat fregante/ghatemplates/esm-lint --exclude jobs.TypeScript --exclude jobs.Node
30 | ```
31 |
32 | ## [node](./node/ci.yml)
33 |
34 | Common Node workflows. You can install them all at once with
35 |
36 | ```sh
37 | npx ghat fregante/ghatemplates/node
38 | ```
39 |
40 | or exclude some
41 |
42 | ```sh
43 | npx ghat fregante/ghatemplates/node --exclude jobs.Test --exclude jobs.Build
44 | ```
45 |
46 | ## [is-dist-up-to-date](./is-dist-up-to-date/is-dist-up-to-date.yml)
47 |
48 | If your distribution/built files need to be committed, this workflow will ensure that they are.
49 |
50 | This is useful when creating GitHub Actions or simply to verify that files have been formatted (a better `prettier --check`, basically)
51 |
52 | ```sh
53 | npx ghat fregante/ghatemplates/is-dist-up-to-date
54 | ```
55 |
56 | Requirements:
57 |
58 | - A `build` npm script (customizable)
59 |
60 | ## [npm-publish](./npm-publish/npm-publish.yml)
61 |
62 | Via [workflow_dispatch](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch) you can automate the release to npm:
63 |
64 | 1. Runs `npm version *` with your specified version
65 | 2. Publishes to npm
66 | 3. Creates the release and changelog with gh-cli
67 |
68 | ```sh
69 | npx ghat fregante/ghatemplates/npm-publish
70 | ```
71 |
72 | Requirements:
73 |
74 | - A `NPM_TOKEN` secret
75 |
76 | ## [action-release](./action-release/action-release.yml)
77 |
78 | Via [workflow_dispatch](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch) you can automate the release and tag updating of a GitHub Action
79 |
80 | 1. Creates the specified tag
81 | 2. Creates the release and changelog with gh-cli
82 | 3. Creates or updates the current major tag (like v1, v2, etc)
83 |
84 | ```sh
85 | npx ghat fregante/ghatemplates/action-release
86 | ```
87 |
--------------------------------------------------------------------------------
/webext/release.yml:
--------------------------------------------------------------------------------
1 | env:
2 | DIRECTORY: distribution
3 | PROJECT_NAME: extension
4 |
5 | name: Release
6 | on:
7 | # You can manually trigger a deployment on GitHub.com
8 | # https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
9 | workflow_dispatch:
10 |
11 | jobs:
12 | Version:
13 | outputs:
14 | created: ${{ env.DAILY_VERSION_CREATED }}
15 | permissions:
16 | contents: write
17 | runs-on: ubuntu-latest
18 | steps:
19 | - uses: actions/checkout@v4
20 | - uses: actions/setup-node@v4
21 | with:
22 | node-version-file: package.json
23 | cache: npm
24 | - run: npm ci
25 | - name: Test and build
26 | run: npm test
27 | - name: Create tag if necessary
28 | uses: fregante/daily-version-action@v2
29 | - name: Update manifest.json with version ${{ env.DAILY_VERSION}}
30 | if: env.DAILY_VERSION_CREATED
31 | run: npx dot-json@1 "$DIRECTORY/manifest.json" version "$DAILY_VERSION"
32 | - name: Ready for "submit" jobs
33 | if: env.DAILY_VERSION_CREATED
34 | uses: actions/upload-artifact@v4
35 | with:
36 | path: ${{ env.DIRECTORY }}
37 | - name: Create release
38 | if: env.DAILY_VERSION_CREATED
39 | env:
40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 | working-directory: ${{ env.DIRECTORY }}
42 | run: |
43 | FILENAME="$PROJECT_NAME-$DAILY_VERSION-for-local-testing-only.zip"
44 | zip -r "$FILENAME" ./*
45 | gh release create "$DAILY_VERSION" --generate-notes "$FILENAME"
46 | Chrome:
47 | if: needs.Version.outputs.created
48 | needs: Version
49 | name: Submit (Chrome)
50 | environment: Chrome
51 | runs-on: ubuntu-latest
52 | steps:
53 | - uses: actions/download-artifact@v4
54 | - run: npx chrome-webstore-upload-cli@3
55 | working-directory: artifact
56 | env:
57 | EXTENSION_ID: ${{ secrets.EXTENSION_ID }}
58 | CLIENT_ID: ${{ secrets.CLIENT_ID }}
59 | CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
60 | REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }}
61 | Firefox:
62 | if: needs.Version.outputs.created
63 | needs: Version
64 | name: Submit (Firefox)
65 | environment: Firefox
66 | runs-on: ubuntu-latest
67 | steps:
68 | - uses: actions/checkout@v4
69 | - uses: actions/download-artifact@v4
70 | - run: git archive --output source.zip HEAD ":!test" ":!.github" && unzip -l source.zip
71 | - run: npx web-ext@8 sign --channel listed --upload-source-code ../source.zip
72 | working-directory: artifact
73 | env:
74 | WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }}
75 | WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }}
76 |
--------------------------------------------------------------------------------