Skip to content

Commit

Permalink
Merge pull request #27 from withastro/version
Browse files Browse the repository at this point in the history
Simplify inputs for v1
  • Loading branch information
natemoo-re authored Sep 26, 2023
2 parents e3193ac + 73877f3 commit 30551ce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 35 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ For more information, please see our complete deployment guide—[Deploy your As
### Inputs

- `path` - Optional: the root location of your Astro project inside the repository.
- `node-version` - Optional: the specific version of Node that should be used to build your site. Defaults to `16`.
- `package-manager` - Optional: the Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. Accepted values: `npm`, `yarn`, `pnpm`, and `bun`.
- `pnpm-version` - Optional: If `package-manager` is set to `pnpm`, use this specific version. Defaults to `7.x.x`.
- `resolve-dep-from-path` - Optional: If the dependency file should be resolved from the root location of your Astro project. Defaults to `true`.
- `node-version` - Optional: the specific version of Node that should be used to build your site. Defaults to `18`.
- `package-manager` - Optional: the Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. Accepted values: `npm`, `yarn`, `pnpm`, and `bun`. A version tag is also accepted, for example `[email protected]`, `pnpm@8`, or `bun@latest`. If not provided, version will default to `latest`.

### Example workflow:

Expand Down Expand Up @@ -46,13 +44,11 @@ jobs:
- name: Checkout your repository using git
uses: actions/checkout@v3
- name: Install, build, and upload your site output
uses: withastro/action@v0
uses: withastro/action@v1
# with:
# path: . # The root location of your Astro project inside the repository. (optional)
# node-version: 16 # The specific version of Node that should be used to build your site. Defaults to 16. (optional)
# package-manager: pnpm # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional)
# pnpm-version: 8.x.x # If `package-manager` is set to `pnpm`, use this specific version. Defaults to `7.x.x`. (optional)
# resolve-dep-from-path: false # If the dependency file should be resolved from the root location of your Astro project. Defaults to `true`. (optional)
# node-version: 18 # The specific version of Node that should be used to build your site. Defaults to 18. (optional)
# package-manager: pnpm@latest # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional)

deploy:
needs: build
Expand Down
44 changes: 18 additions & 26 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,18 @@ branding:
icon: "box"
color: "orange"
inputs:
path:
description: "Path of the directory containing your site"
required: false
default: "."
node-version:
description: "The node version to use"
required: false
default: "16"
default: "18"
package-manager:
description: "If not automatically detectable, you may specify your preferred package manager"
description: "You may specify your preferred package manager (one of `npm | yarn | pnpm | bun` and an optional `@<version>` tag). Otherwise, the package manager will be automatically detected."
required: false
default: ""
pnpm-version:
description: "If package-manager is pnpm, use this specific version. Defaults to latest"
required: false
default: "7.x.x"
resolve-dep-from-path:
description: "If the dependency file is located inside the folder specified by path"
type: boolean
path:
description: "Path of the directory containing your site"
required: false
default: true
default: "."

runs:
using: composite
Expand All @@ -36,51 +27,52 @@ runs:
run: |
len=`echo $INPUT_PM | wc -c`
if [ $len -gt 1 ]; then
echo "PACKAGE_MANAGER=$INPUT_PM" >> $GITHUB_ENV
PACKAGE_MANAGER=$(echo "$INPUT_PM" | grep -o '^[^@]*')
VERSION=$(echo "$INPUT_PM" | grep -o '@.*' | sed 's/^@//')
# Set default VERSION if not provided
if [ -z "$VERSION" ]; then
VERSION="latest"
fi
echo "PACKAGE_MANAGER=$PACKAGE_MANAGER" >> $GITHUB_ENV
elif [ $(find "." -name "pnpm-lock.yaml") ]; then
echo "PACKAGE_MANAGER=pnpm" >> $GITHUB_ENV
echo "LOCKFILE=pnpm-lock.yaml" >> $GITHUB_ENV
elif [ $(find "." -name "yarn.lock") ]; then
echo "PACKAGE_MANAGER=yarn" >> $GITHUB_ENV
echo "LOCKFILE=yarn.lock" >> $GITHUB_ENV
elif [ $(find "." -name "package-lock.json") ]; then
VERSION="latest"
echo "PACKAGE_MANAGER=npm" >> $GITHUB_ENV
echo "LOCKFILE=package-lock.json" >> $GITHUB_ENV
elif [ $(find "." -name "bun.lockb") ]; then
VERSION="latest"
echo "PACKAGE_MANAGER=bun" >> $GITHUB_ENV
echo "LOCKFILE=bun.lockb" >> $GITHUB_ENV
else
echo "No lockfile found.
Please specify your preferred \"package-manager\" in the action configuration."
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Setup PNPM
if: ${{ env.PACKAGE_MANAGER == 'pnpm' }}
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v2
with:
version: ${{ inputs.pnpm-version }}
version: ${{ env.VERSION }}

- name: Setup Bun
if: ${{ env.PACKAGE_MANAGER == 'bun' }}
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
bun-version: ${{ env.VERSION }}

- name: Setup Node
uses: actions/setup-node@v3
if: inputs.resolve-dep-from-path == true
with:
node-version: ${{ inputs.node-version }}
cache: ${{ env.PACKAGE_MANAGER }}
cache-dependency-path: "${{ inputs.path }}/${{ env.LOCKFILE }}"

- name: Setup Node
uses: actions/setup-node@v3
if: inputs.resolve-dep-from-path == false
with:
node-version: ${{ inputs.node-version }}
cache: ${{ env.PACKAGE_MANAGER }}

- name: Install
shell: "bash"
run: |
Expand Down

0 comments on commit 30551ce

Please sign in to comment.