-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: switch to using package_json
for interacting with package.json
#466
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b7403ae
feat: switch to using `package_json` for interacting with `package.json`
G-Rath f7be95b
refactor: replace direct reads of `package.json` with `package_json` …
G-Rath a2ebea5
fix: use `PackageJson` to generate native commands for scripts
G-Rath fd1cbf2
feat: allow using any js package manager
G-Rath 8033f3c
ci: test against the three main package managers
G-Rath b3fe2cf
fix: don't `sort-package-json` for now
G-Rath db67841
ci: get rid of node cache all together
G-Rath 98cb7d0
ci: use a ruby script to create fake js package managers
G-Rath dc878cd
fix: use bang manager methods
G-Rath c69482c
chore: use `direnv` to set up fake js package managers locally
G-Rath 8b68756
feat: support Yarn Berry
G-Rath 89715af
fix: update how Jest major version is determined
G-Rath 471ab18
fix: add missing dependencies
G-Rath 8513f46
feat: use new headless rendering mode
G-Rath ad38604
fix: always copy a babel config
G-Rath 93a71bf
fix: support lighthouse with Yarn Berry
G-Rath 4d0c698
feat: support `bun` as a package manager
G-Rath 5ea3949
ci: use specific version of osv-detector to avoid rate limiting
G-Rath 52b804e
ci: reduce noise from `npm install`
G-Rath e252e48
fix: add missing package dependency extensions for Yarn Berry with PnP
G-Rath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,13 @@ concurrency: | |
# should be granted per job as needed using a dedicated `permissions` block | ||
permissions: {} | ||
|
||
env: | ||
# reduces noise from npm install | ||
DISABLE_OPENCOLLECTIVE: true | ||
OPEN_SOURCE_CONTRIBUTOR: true | ||
NPM_CONFIG_FUND: false | ||
NPM_CONFIG_AUDIT: false | ||
|
||
jobs: | ||
audit_dependencies: | ||
permissions: | ||
|
@@ -29,6 +36,8 @@ jobs: | |
persist-credentials: false | ||
- name: Audit dependencies for security vulnerabilities | ||
uses: g-rath/check-with-osv-detector@main | ||
with: | ||
osv-detector-version: 0.13.0 | ||
test: | ||
permissions: | ||
contents: read | ||
|
@@ -70,6 +79,24 @@ jobs: | |
# how many fail) | ||
fail-fast: false | ||
matrix: | ||
js_package_manager: | ||
- name: npm | ||
installer: npm | ||
- name: yarn_berry | ||
installer: yarn | ||
linker: pnp | ||
- name: yarn_berry | ||
installer: yarn | ||
linker: node-modules | ||
- name: yarn_berry | ||
installer: yarn | ||
linker: pnpm | ||
- name: yarn_classic | ||
installer: yarn | ||
- name: pnpm | ||
installer: pnpm | ||
- name: bun | ||
installer: bun | ||
variant: | ||
- name: defaults | ||
config_path: 'ackama_rails_template.config.yml' | ||
|
@@ -131,6 +158,8 @@ jobs: | |
# this ensures that osv-detector is available for running bin/ci-run | ||
- name: Check dependencies for vulnerabilities (and setup osv-detector) | ||
uses: g-rath/check-with-osv-detector@main | ||
with: | ||
osv-detector-version: 0.13.0 | ||
|
||
# this ensures that actionlint is available for running bin/ci-run | ||
- name: Setup ActionLint | ||
|
@@ -142,9 +171,11 @@ jobs: | |
- name: Install NodeJS | ||
uses: actions/setup-node@v4 | ||
with: | ||
cache: 'yarn' | ||
node-version-file: '.node-version' | ||
|
||
- name: install package manager | ||
run: npm i -g ${{ matrix.js_package_manager.installer }} | ||
|
||
# We don't cache gems or JS packages because we are actually testing how | ||
# installation and setup works in this project so, while caching would | ||
# make CI faster, it might hide problems. | ||
|
@@ -161,6 +192,9 @@ jobs: | |
git config --global user.email "[email protected]" | ||
git config --global user.name "Your Name" | ||
|
||
# prettier-ignore | ||
- run: ./ci/bin/create-fake-js-package-managers ${{ matrix.js_package_manager.installer }} | ||
|
||
- name: Run CI script | ||
env: | ||
# Remember that your app name becomes a top-level constant in the | ||
|
@@ -173,4 +207,7 @@ jobs: | |
PGUSER: postgres | ||
PGPASSWORD: postgres | ||
PGHOST: localhost | ||
PACKAGE_JSON_FALLBACK_MANAGER: ${{ matrix.js_package_manager.name }} | ||
PACKAGE_JSON_YARN_BERRY_LINKER: | ||
${{ matrix.js_package_manager.linker }} | ||
run: ./ci/bin/build-and-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# creates a set of fake JavaScript package managers in a temporary bin | ||
# directory for GitHub Actions, _excluding_ the one passed in as an | ||
# argument in order to assert that only that package manager is used | ||
|
||
require "fileutils" | ||
require "tmpdir" | ||
|
||
# setup the bin directory we want to use | ||
bin_dir = "tmp/fake-bin" | ||
|
||
if ENV["GITHUB_ACTIONS"] | ||
bin_dir = Dir.mktmpdir("rails-template-") | ||
|
||
puts "adding #{bin_dir} to GITHUB_PATH..." | ||
|
||
File.write(ENV.fetch("GITHUB_PATH"), "#{bin_dir}\n", mode: "a+") | ||
elsif system("direnv --version > /dev/null 2>&1") | ||
envrc_content = "PATH_add #{bin_dir}\n" | ||
|
||
if File.exist?(".envrc") && File.read(".envrc").include?(envrc_content) | ||
puts "'#{envrc_content.strip}' already exists in .envrc" | ||
else | ||
File.write(".envrc", envrc_content, mode: "a") | ||
puts "Added '#{envrc_content.strip}' to .envrc" | ||
end | ||
|
||
# ensure the .envrc is allowed | ||
system("direnv allow") | ||
end | ||
|
||
managers = %w[npm yarn pnpm bun] | ||
manager_in_use = ARGV[0] || "" | ||
|
||
if manager_in_use.empty? | ||
manager_in_use = ENV.fetch("PACKAGE_JSON_FALLBACK_MANAGER", "") | ||
.delete_suffix("_berry") | ||
.delete_suffix("_classic") | ||
end | ||
|
||
Dir.chdir(bin_dir) do | ||
managers.each do |manager| | ||
if manager == manager_in_use | ||
# ensure that the manager is not stubbed in case we've changed managers | ||
FileUtils.rm_f(manager) | ||
|
||
next | ||
end | ||
|
||
puts "creating #{bin_dir}/#{manager}..." | ||
File.write( | ||
manager, | ||
<<~CONTENTS | ||
#!/usr/bin/env node | ||
|
||
throw new Error("(#{manager}) this is not the package manager you're looking for..."); | ||
CONTENTS | ||
) | ||
File.chmod(0o755, manager) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
variants/backend-base/lib/tasks/assets.rake → ...nts/backend-base/lib/tasks/assets.rake.tt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
copy_file "variants/backend-base/lib/tasks/coverage.rake", "lib/tasks/coverage.rake" | ||
copy_file "variants/backend-base/lib/tasks/assets.rake", "lib/tasks/assets.rake" | ||
copy_file "variants/backend-base/lib/tasks/app.rake", "lib/tasks/app.rake" | ||
copy_file "variants/backend-base/lib/tasks/dev.rake", "lib/tasks/dev.rake" | ||
|
||
template "variants/backend-base/lib/tasks/assets.rake.tt", "lib/tasks/assets.rake", force: true |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realised while doing the tests for Shakapacker that I could have the bin scripts as Ruby files instead of JS, and that I didn't necessarily need to modify PATH in the manner this script currently does since we're running things via Ruby - so I should be able to just modify the
PATH
variable in memory for the actual Ruby system calls that run the external commands.I think what I've got currently would be fine to land but if I have a chance I might look into refactoring this to see if the result is cleaner - here's where I'm doing it in Shakapacker for reference: https://github.com/shakacode/shakapacker/pull/349/files#diff-c1038565809dc87afa90260271577a6eb687b351413beba0ff487d1b9e5b8494R307