Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache gem install fontist, cache ~/.fontist, and add semver support #6

Merged
merged 37 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5da65b6
test
jcbhmr Jan 26, 2024
2e4d0fa
use bun workflows
jcbhmr Jan 26, 2024
124eb90
proper inputs & outputs
jcbhmr Jan 26, 2024
fe98dc6
use tags instead of releases
jcbhmr Jan 26, 2024
5e42ea3
subdir of extracted
jcbhmr Jan 26, 2024
33f30ce
save
jcbhmr Jan 26, 2024
9df307f
set action.yml defaults in env vars
jcbhmr Jan 26, 2024
4863584
create files before use
jcbhmr Jan 26, 2024
8282e11
log env and path
jcbhmr Jan 26, 2024
f89dafc
proper command
jcbhmr Jan 26, 2024
e238f70
try this
jcbhmr Jan 26, 2024
4464e27
try this
jcbhmr Jan 26, 2024
c6de7d6
pass through inputs
jcbhmr Jan 26, 2024
2350c70
touch file
jcbhmr Jan 26, 2024
6d6eac6
shell field
jcbhmr Jan 26, 2024
73118e8
strip v prefix
jcbhmr Jan 26, 2024
8883124
bindir
jcbhmr Jan 26, 2024
9f8585a
fmt
jcbhmr Jan 26, 2024
ee89e82
different path strat
jcbhmr Jan 26, 2024
59c21cf
just bindir
jcbhmr Jan 26, 2024
7ce2bd7
update desc
jcbhmr Jan 26, 2024
49d74f4
add desc to action.yml
jcbhmr Jan 26, 2024
62a93a3
dump env
jcbhmr Jan 26, 2024
e7989b3
try wrapper script
jcbhmr Jan 26, 2024
1df950d
chmod
jcbhmr Jan 26, 2024
3b68b98
quote $@
jcbhmr Jan 26, 2024
2558cd4
try this
jcbhmr Jan 26, 2024
749f8dc
compile post too
jcbhmr Jan 27, 2024
bf557f5
no more setup ruby
jcbhmr Jan 27, 2024
6d5d012
try this
jcbhmr Jan 27, 2024
2302647
version dep
jcbhmr Jan 27, 2024
b954994
process,exit()
jcbhmr Jan 27, 2024
8f7f32b
reorganize with more logging
jcbhmr Jan 27, 2024
6b38434
try with cache-dependency-path?
jcbhmr Jan 27, 2024
a76f9b9
add docs for cache inputs
jcbhmr Jan 27, 2024
ac10982
add note about bun on windows
jcbhmr Jan 27, 2024
78f46a3
Update README.md on `cache-hit`
ronaldtse Jan 30, 2024
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
10 changes: 10 additions & 0 deletions .github/workflows/publish-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ jobs:
contents: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun run build
- run: rm -rf node_modules
- uses: actions4git/setup-git@v1
- run: git add -Af && git commit -m 'npm run build'
- run: git tag -f "$TAG" && git push -f origin "$TAG"
env:
TAG: ${{ github.event.release.tag_name }}
- uses: actions/[email protected]
with:
source-tag: ${{ github.event.release.tag_name }}
6 changes: 5 additions & 1 deletion .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# os: [ubuntu-latest, macos-latest, windows-latest]
Copy link

Choose a reason for hiding this comment

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

Are there some issues on Windows discovered?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's because bun is not supported on Windows.

os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun run build
- uses: ./
- run: fontist list "Fira Code"
175 changes: 175 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
34 changes: 28 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@

💎 Uses Ruby to install the fontist Ruby gem \
🟦 Works with Windows \
🔠 Lets you install additional fonts
🐧 Works with Ubuntu \
🍎 Works with macOS \
⚡ Caches installation in `$RUNNER_TOOL_CACHE` and/ior the workflow cache \
📐 Caches `~/.fontist` font installs by default using `manifest.yml`

## Usage

![GitHub Actions](https://img.shields.io/static/v1?style=for-the-badge&message=GitHub+Actions&color=2088FF&logo=GitHub+Actions&logoColor=FFFFFF&label=)
![GitHub](https://img.shields.io/static/v1?style=for-the-badge&message=GitHub&color=181717&logo=GitHub&logoColor=FFFFFF&label=)

**🚀 Here's what you're after:**

```yml
on: push
jobs:
Expand All @@ -31,19 +36,36 @@ jobs:
- run: fontist install "Fira Code"
```

**⚠️ This action takes a while** (~1 minute). There's currently **no caching**. [Caching is planned for the future.](#TODO)
💡 You can use `fontist manifest-install manifest.yml` to install fonts listed in a manifest file similar to `package.json`, `requirements.txt`, and `Cargo.toml`.

### Inputs

- **`setup-ruby`:** Whether or not to run [ruby/setup-ruby](https://github.com/ruby/setup-ruby) or to assume that the user has supplied an appropriate global Ruby installation. Defaults to `true`. Set this to `false` to provide your own custom Ruby installation.
CAMOBAP marked this conversation as resolved.
Show resolved Hide resolved
- **`fontist-version`:** The version of Fontist to install. This can be an exact version lile `1.10.0` or a semver range such as `1.x` or `~1.15.0`. The default value is `latest`.

- **`fontist-token`:** The GitHub token to use when fetching the version list from fontist/fontist. You shouldn't have to touch this. The default is the `github.token` if you're on github.com or unauthenticated (rate limited) if you're not on github.com.

- **`cache`:** Whether or not to use [@actions/cache](https://www.npmjs.com/package/@actions/cache) to cache things in the GitHub workflow cache. This is enabled by default.

- **`cache-dependency-path`:** A multiline list of globs to use to derive the `~/.fontist` cache key. The default is `manifest.yml` and `manifest.yaml`. If no files are matched at runtime then the `~/.fontist` folder will not be cached.

- **`fontist-version`:** An exact version of the fontist Ruby gem to install. Defaults to `1.19.0`.
### Outputs

- **`fontist-version`:** The version of Fontist that was installed. This will be something like `1.10.0` or similar.

- **`cache-hit`:** Whether or not Fontist was restored from the runner's cache or download anew.
ronaldtse marked this conversation as resolved.
Show resolved Hide resolved

## Development

![GNU Bash](https://img.shields.io/static/v1?style=for-the-badge&message=GNU+Bash&color=4EAA25&logo=GNU+Bash&logoColor=FFFFFF&label=)
![Bun](https://img.shields.io/static/v1?style=for-the-badge&message=Bun&color=000000&logo=Bun&logoColor=FFFFFF&label=)
![Node.js](https://img.shields.io/static/v1?style=for-the-badge&message=Node.js&color=339933&logo=Node.js&logoColor=FFFFFF&label=)
![Ruby](https://img.shields.io/static/v1?style=for-the-badge&message=Ruby&color=CC342D&logo=Ruby&logoColor=FFFFFF&label=)

This action tries to restore the result of `gem install fontist` from both the `$RUNNER_TOOL_CACHE` as well as the workflow cache via [@actions/cache](https://www.npmjs.com/package/@actions/cache). It then tries to restore the `~/.fontist` folder local cache from the workflow cache.

**How do I test it?** \
Open a PR (even a draft one works) and some magic GitHub Actions will run to test your changes.

TODO: Add development section
Note that since [Bun doesn't support Windows yet](https://github.com/oven-sh/bun/issues/43) we can't run the `bun build` command on Windows runners. Don't worry! The action should still work ok since Bun is only used for the build step; it runs using `node <the-js-file>` via `using: node20` in both testing and releases. Once Bun adds Windows support remember to add back the Windows tests. 😉

## Contributions

Expand Down
35 changes: 21 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ branding:
color: purple

inputs:
setup-ruby:
fontist-version:
description: The version of Fontist to install. This can be an exact version lile '1.10.0' or a semver range such as '1.x' or '~1.15.0'. The default value is 'latest'.
default: latest
fontist-token:
description: The GitHub token to use when fetching the version list from fontist/fontist. You shouldn't have to touch this. The default is the 'github.token' if you're on github.com or unauthenticated (rate limited) if you're not on github.com.
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
cache:
description: Whether or not to use @actions/cache to cache things in the GitHub workflow cache. This is enabled by default.
default: true
cache-dependency-path:
description: A multiline list of globs to use to derive the '~/.fontist' cache key. The default is 'manifest.yml' and 'manifest.yaml'. If no files are matched at runtime then the '~/.fontist' folder will not be cached.
default: manifest.y{a,}ml

outputs:
fontist-version:
default: "1.19.0"
description: The version of Fontist that was installed. This will be something like '1.10.0' or similar.
value: ${{ steps.setup-fontist.outputs.fontist-version }}
cache-hit:
description: Whether or not Fontist was restored from the runner's cache or download anew.
value: ${{ steps.setup-fontist.outputs.cache-hit }}

runs:
using: composite
steps:
- if: inputs.setup-ruby == 'true'
uses: ruby/setup-ruby@v1
with:
ruby-version: ruby
- shell: bash
run: |
gem install fontist --version "$(printenv INPUT_FONTIST-VERSION)"
fontist update
env:
INPUT_FONTIST-VERSION: ${{ inputs.fontist-version }}
using: node20
main: dist/main.js
post: dist/post.js
Binary file added bun.lockb
Binary file not shown.
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"type": "module",
"packageManager": "[email protected]",
"dependencies": {
"@actions/cache": "^3.2.3",
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@actions/glob": "^0.4.0",
"@actions/tool-cache": "^2.0.1",
"@octokit/auth-unauthenticated": "^5.0.1",
"execa": "^8.0.1",
"semver": "^7.5.4"
},
"devDependencies": {
"@types/node": "^20.10.4",
"@types/semver": "^7.5.6",
"prettier": "^3.1.1",
"typescript": "^5.3.3",
"@types/bun": "latest"
},
"scripts": {
"build": "bun build ./src/main.ts ./src/post.ts --outdir=dist --target=node",
"format": "prettier -w .",
"lint": "tsc --noEmit"
}
}
Loading
Loading