Skip to content

Commit

Permalink
Introduce v4.0.0 (#13)
Browse files Browse the repository at this point in the history
* Introduce the `inject-subpath-exports` action (closes #12)

* Introduce the `check-subpath-exports` action

* Introduce the `publish-github-pages` action

* Introduce the `setup-nodejs-context` action

* Introduce the `install-system-packages` action

* Simplify `find-critical-todos` and its documentation

* Add the `registry-url` input to all the npm-related actions

* Add the `enforce-esm` input to `verify-npm-package`

* Check that package.json exists as a prerequisite for npm actions

* Improve the tests and the related projects

* Simplify all the `find` calls

* Fix whitespace and formatting

* Improve the output messages

* Use `jq` instead of `cat` to print out `package.json`

* Extend the documentation

* Explain the permission required by `tag-and-release`

* Add standard emojis to the READMEs

* Remove the misleading `required` attribute from action inputs

* Update repository description

* Update the action diagram
  • Loading branch information
giancosta86 authored Oct 20, 2024
1 parent b427a88 commit b137b48
Show file tree
Hide file tree
Showing 68 changed files with 1,502 additions and 399 deletions.
4 changes: 2 additions & 2 deletions .github/test-actions/test-artifact-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ runs:
version="${{ steps.version-detector.outputs.version }}"
if ! cat ./tests/unknown-tech/some-descriptor.txt | grep -q "v$version"
then
then
echo "❌Error while injecting the version into a custom descriptor!" >&2
exit 1
fi
Expand All @@ -82,7 +82,7 @@ runs:
version="${{ steps.version-detector.outputs.version }}"
if ! cat ./tests/unknown-tech/some-descriptor.txt | grep -q "'$version';"
then
then
echo "❌The version was not injected globally into a custom descriptor!" >&2
exit 1
fi
56 changes: 56 additions & 0 deletions .github/test-actions/test-check-subpath-exports/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Test check-subpath-exports

runs:
using: composite
steps:
- name: When the "exports" field is missing
uses: ./.github/test-actions/test-check-subpath-exports/scenario
with:
jq-operation: del(.exports)

- name: When the "exports" field is present but empty
uses: ./.github/test-actions/test-check-subpath-exports/scenario
with:
jq-operation: .exports={}

- name: When the "exports" field is a string
uses: ./.github/test-actions/test-check-subpath-exports/scenario
with:
jq-operation: .exports="./src/beta/index.js"

- name: When the "exports" field contains a string field
uses: ./.github/test-actions/test-check-subpath-exports/scenario
with:
jq-operation: |
.exports={
"beta": "./src/beta/index.js"
}
- name: When the "exports" field contains an object field
uses: ./.github/test-actions/test-check-subpath-exports/scenario
with:
jq-operation: |
.exports={
"beta": {
"import": "./src/beta/index.js",
"default": "./src/beta/index.js"
}
}
- name: When the "exports" field contains multiple fields
uses: ./.github/test-actions/test-check-subpath-exports/scenario
with:
jq-operation: |
.exports={
"alpha": {
"import": "./src/alpha/index.ts",
"default": "./src/alpha/index.ts"
},
"beta": {
"import": "./src/beta/index.js",
"default": "./src/beta/index.js"
},
"omega": "./src/omega/index.ts"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Update and check subpath exports in the npm test project

inputs:
jq-operation:
description: The operation altering the package.json descriptor

runs:
using: composite
steps:
- name: Run the requested jq operation on package.json
shell: bash
working-directory: ./tests/npm-package
run: |
jq '${{ inputs.jq-operation }}' package.json | sponge package.json
echo "🔎The 'exports' field is:"
jq '.exports' package.json
- uses: ./actions/check-subpath-exports
with:
project-directory: ./tests/npm-package
10 changes: 5 additions & 5 deletions .github/test-actions/test-detect-branch-version/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ runs:
branch="${{ steps.detector.outputs.branch }}"
echo "🔎Branch retrieved from action: '$branch'"
if [[ -z "$branch" ]]
if [[ -z "$branch" ]]
then
echo "❌The branch should not be empty!" >&2
exit 1
Expand All @@ -26,7 +26,7 @@ runs:
echo "🔎Head ref in pull request: '$headRef'"
if [[ "$branch" != "$headRef" ]]
if [[ "$branch" != "$headRef" ]]
then
echo "❌The branch ('$branch') should match the head_ref ('$headRef')!" >&2
exit 1
Expand All @@ -38,7 +38,7 @@ runs:
version="${{ steps.detector.outputs.version }}"
echo "🔎Version retrieved from action: '$version'"
if [[ -z "$version" ]]
if [[ -z "$version" ]]
then
echo "❌The version should not be empty!" >&2
exit 1
Expand All @@ -50,7 +50,7 @@ runs:
escapedVersion="${{ steps.detector.outputs.escaped-version }}"
echo "🔎Escaped version retrieved from action: '$escapedVersion'"
if ! echo "$escapedVersion" | grep -Pq "\\\."
if ! echo "$escapedVersion" | grep -Pq "\\\."
then
echo "❌The escaped version should include '\.'!" >&2
exit 1
Expand All @@ -62,7 +62,7 @@ runs:
major="${{ steps.detector.outputs.major }}"
echo "🔎Major version component: '$major'"
if [[ -z "$major" ]]
if [[ -z "$major" ]]
then
echo "❌The major component should not be empty!" >&2
exit 1
Expand Down
16 changes: 8 additions & 8 deletions .github/test-actions/test-detect-project-tech/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runs:
tech="${{ steps.detect-rust-crate.outputs.project-tech }}"
echo "🔎Technology retrieved for 🦀Rust: '$tech'"
if [[ "$tech" != "rust" ]]
if [[ "$tech" != "rust" ]]
then
echo "❌Incorrect project tech!" >&2
exit 1
Expand All @@ -26,7 +26,7 @@ runs:
artifactDescriptor="${{ steps.detect-rust-crate.outputs.artifact-descriptor }}"
echo "🔎Artifact descriptor retrieved for 🦀Rust: '$artifactDescriptor'"
if [[ "$artifactDescriptor" != "Cargo.toml" ]]
if [[ "$artifactDescriptor" != "Cargo.toml" ]]
then
echo "❌Incorrect artifact descriptor!" >&2
exit 1
Expand All @@ -43,7 +43,7 @@ runs:
tech="${{ steps.detect-rust-wasm.outputs.project-tech }}"
echo "🔎Technology retrieved for 🦀Rust 🌐web assembly: '$tech'"
if [[ "$tech" != "rust" ]]
if [[ "$tech" != "rust" ]]
then
echo "❌Incorrect project tech!" >&2
exit 1
Expand All @@ -55,7 +55,7 @@ runs:
artifactDescriptor="${{ steps.detect-rust-wasm.outputs.artifact-descriptor }}"
echo "🔎Artifact descriptor retrieved for 🦀Rust 🌐web assembly: '$artifactDescriptor'"
if [[ "$artifactDescriptor" != "Cargo.toml" ]]
if [[ "$artifactDescriptor" != "Cargo.toml" ]]
then
echo "❌Incorrect artifact descriptor!" >&2
exit 1
Expand All @@ -72,7 +72,7 @@ runs:
tech="${{ steps.detect-nodejs-package.outputs.project-tech }}"
echo "🔎Technology retrieved for 📦NodeJS: '$tech'"
if [[ "$tech" != "nodejs" ]]
if [[ "$tech" != "nodejs" ]]
then
echo "❌Incorrect project tech!" >&2
exit 1
Expand All @@ -84,7 +84,7 @@ runs:
artifactDescriptor="${{ steps.detect-nodejs-package.outputs.artifact-descriptor }}"
echo "🔎Artifact descriptor retrieved for 📦NodeJS: '$artifactDescriptor'"
if [[ "$artifactDescriptor" != "package.json" ]]
if [[ "$artifactDescriptor" != "package.json" ]]
then
echo "❌Incorrect artifact descriptor!" >&2
exit 1
Expand All @@ -101,7 +101,7 @@ runs:
tech="${{ steps.detect-unknown-tech.outputs.project-tech }}"
echo "🔎Technology retrieved for 🎁unknown stack: '$tech'"
if [[ ! -z "$tech" ]]
if [[ ! -z "$tech" ]]
then
echo "❌Incorrect project tech!" >&2
exit 1
Expand All @@ -113,7 +113,7 @@ runs:
artifactDescriptor="${{ steps.detect-unknown-tech.outputs.artifact-descriptor }}"
echo "🔎Artifact descriptor retrieved for 🎁unknown stack: '$artifactDescriptor'"
if [[ ! -z "$artifactDescriptor" ]]
if [[ ! -z "$artifactDescriptor" ]]
then
echo "❌Incorrect artifact descriptor!" >&2
exit 1
Expand Down
20 changes: 10 additions & 10 deletions .github/test-actions/test-extract-rust-snippets/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ runs:
testFile="readme_test_1.rs"
echo "🔎Inspecting the content of the first test file..."
grep 'Alpha' "$testFile"
grep 'Beta' "$testFile"
grep 'main().unwrap();' "$testFile"
grep -q 'Alpha' "$testFile"
grep -q 'Beta' "$testFile"
grep -q 'main().unwrap();' "$testFile"
echo "✅First test file OK!"
- name: The second test must contain the expected Rust source code
Expand All @@ -72,10 +72,10 @@ runs:
testFile="readme_test_2.rs"
echo "🔎Inspecting the content of the second test file..."
grep 'Gamma' "$testFile"
grep 'Delta' "$testFile"
grep 'Epsilon' "$testFile"
grep 'main().unwrap();' "$testFile"
grep -q 'Gamma' "$testFile"
grep -q 'Delta' "$testFile"
grep -q 'Epsilon' "$testFile"
grep -q 'main().unwrap();' "$testFile"
echo "✅Second test file OK!"
- name: The third test must contain the expected Rust source code
Expand All @@ -85,7 +85,7 @@ runs:
testFile="readme_test_3.rs"
echo "🔎Inspecting the content of the third test file..."
grep 'Sigma' "$testFile"
grep 'Tau' "$testFile"
grep 'main().unwrap();' "$testFile"
grep -q 'Sigma' "$testFile"
grep -q 'Tau' "$testFile"
grep -q 'main().unwrap();' "$testFile"
echo "✅Third test file OK!"
4 changes: 2 additions & 2 deletions .github/test-actions/test-find-critical-todos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ runs:
uses: ./actions/find-critical-todos
with:
root-directory: ./tests/unknown-tech/src
source-file-regex: '\.(js|txt)$'
source-file-regex: \.(js|txt)$
crash-on-found: false

- name: Critical TODOs should be found when existing
Expand All @@ -26,5 +26,5 @@ runs:
uses: ./actions/find-critical-todos
with:
root-directory: ./tests/rust-crate/src
source-file-regex: ".*"
source-file-regex: .*
crash-on-found: true
101 changes: 101 additions & 0 deletions .github/test-actions/test-inject-subpath-exports/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Test inject-subpath-exports

runs:
using: composite
steps:
- name: Setup environment variables
shell: bash
run: |
rootIndexFile="src/index.ts"
echo "rootIndexFile=$rootIndexFile" >> $GITHUB_ENV
- name: Backup package descriptor
shell: bash
working-directory: ./tests/npm-package
run: cp package.json package.json.original

- name: Ensure the root index file is initially missing
shell: bash
working-directory: ./tests/npm-package
run: |
rm -f "$rootIndexFile"
- name: Run with prefer-index mode - when the root index file is missing
uses: ./actions/inject-subpath-exports
with:
project-directory: ./tests/npm-package
mode: prefer-index

- name: A subpath export should be generated for each subdirectory
shell: bash
working-directory: ./tests/npm-package
run: |
echo "🔎Asserting injected subpath exports from subdirectories only..."
grep -q '"./alpha"' package.json
grep -q '"./beta"' package.json
grep -q '"./omega"' package.json
[[ "$(jq -r '.exports."./alpha".types' package.json)" == "./dist/alpha/index.d.ts" ]] || exit 1
[[ "$(jq -r '.exports."./alpha".import' package.json)" == "./dist/alpha/index.js" ]] || exit 1
! grep -q '"."' package.json
! grep -q '"./sigma"' package.json
echo "✅OK!"
- name: Restore package.json and add a root index file
shell: bash
working-directory: ./tests/npm-package
run: |
cp package.json.original package.json
touch "$rootIndexFile"
- name: Run again with prefer-index mode - now that the root index exists
uses: ./actions/inject-subpath-exports
with:
project-directory: ./tests/npm-package
mode: prefer-index

- name: A subpath export should be generated only for the root index
shell: bash
working-directory: ./tests/npm-package
run: |
echo "🔎Asserting injected subpath export for root index only..."
! grep -q '"./alpha"' package.json
! grep -q '"./beta"' package.json
! grep -q '"./omega"' package.json
grep -q '"."' package.json
[[ "$(jq -r '.exports.".".types' package.json)" == "./dist/index.d.ts" ]] || exit 1
[[ "$(jq -r '.exports.".".import' package.json)" == "./dist/index.js" ]] || exit 1
! grep -q '"./sigma"' package.json
echo "✅OK!"
- name: Restore package descriptor with custom export
shell: bash
working-directory: ./tests/npm-package
run: |
cp package.json.original package.json
jq '.exports += {"./my-export": {"types": "./dist/my-export/index.d.ts", "import": "./dist/my-export/index.js"}}' package.json | sponge package.json
- name: Run action with 'all' mode
uses: ./actions/inject-subpath-exports
with:
project-directory: ./tests/npm-package
mode: all

- name: Subpath exports should be generated for both root index and subdirectories
shell: bash
working-directory: ./tests/npm-package
run: |
echo "🔎Asserting that all exports exist, including the manual ones..."
grep -q '"./my-export"' package.json
grep -q '"./alpha"' package.json
grep -q '"./beta"' package.json
grep -q '"./omega"' package.json
grep -q '"."' package.json
! grep -q '"./sigma"' package.json
echo "✅OK!"
Loading

0 comments on commit b137b48

Please sign in to comment.