├── .github ├── release-drafter.yml └── workflows │ ├── draft-release.yml │ └── release.yml ├── LICENSE ├── README.md └── action.yml /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name-template: "v$RESOLVED_VERSION" 3 | tag-template: "v$RESOLVED_VERSION" 4 | template: | 5 | # Changelog 6 | 7 | $CHANGES 8 | 9 | See details of [all code changes](https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION) since previous release. 10 | categories: 11 | - title: "🚀 Features" 12 | labels: 13 | - "feature" 14 | - "enhancement" 15 | - title: "🐛 Bug Fixes" 16 | labels: 17 | - "fix" 18 | - "bugfix" 19 | - "bug" 20 | - title: "🧰 Maintenance" 21 | labels: 22 | - "infrastructure" 23 | - "automation" 24 | - "documentation" 25 | - title: "🏎 Performance" 26 | label: "performance" 27 | change-template: "- $TITLE @$AUTHOR (#$NUMBER)" 28 | version-resolver: 29 | major: 30 | labels: 31 | - "type: breaking" 32 | minor: 33 | labels: 34 | - "type: enhancement" 35 | patch: 36 | labels: 37 | - "type: bug" 38 | - "type: maintenance" 39 | - "type: documentation" 40 | default: patch 41 | -------------------------------------------------------------------------------- /.github/workflows/draft-release.yml: -------------------------------------------------------------------------------- 1 | name: Draft release 2 | on: 3 | push: 4 | branches: 5 | - main 6 | 7 | jobs: 8 | draft-release: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: release-drafter/release-drafter@v5 13 | env: 14 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 15 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | release: 4 | types: [released, edited] 5 | workflow_dispatch: 6 | inputs: 7 | TAG_NAME: 8 | description: "Tag name that the major tag will point to" 9 | required: true 10 | 11 | env: 12 | TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} 13 | 14 | permissions: 15 | contents: write 16 | 17 | jobs: 18 | update_tag: 19 | name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} changes 20 | runs-on: ubuntu-latest 21 | environment: 22 | # Note: this environment is protected 23 | name: Release 24 | steps: 25 | - name: Update the ${{ env.TAG_NAME }} tag 26 | id: update-major-tag 27 | uses: actions/publish-action@v0.3.0 28 | with: 29 | source-tag: ${{ env.TAG_NAME }} 30 | slack-webhook: ${{ secrets.SLACK_WEBHOOK }} 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2022 The Astro Technology Company 2 | 3 | Permission is hereby granted, free of 4 | charge, to any person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, copy, modify, merge, 7 | publish, distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to the 9 | following conditions: 10 | 11 | The above copyright notice and this permission notice 12 | (including the next paragraph) shall be included in all copies or substantial 13 | portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 18 | EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | --- 24 | 25 | Portions of this code adapted from https://github.com/actions/upload-pages-artifact 26 | 27 | MIT License 28 | 29 | Copyright (c) 2022 GitHub, Inc. 30 | 31 | Permission is hereby granted, free of charge, to any person obtaining a copy 32 | of this software and associated documentation files (the "Software"), to deal 33 | in the Software without restriction, including without limitation the rights 34 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 35 | copies of the Software, and to permit persons to whom the Software is 36 | furnished to do so, subject to the following conditions: 37 | 38 | The above copyright notice and this permission notice shall be included in all 39 | copies or substantial portions of the Software. 40 | 41 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 44 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 45 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 46 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 47 | SOFTWARE. 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deploy Astro to GitHub Pages 2 | 3 | This action for [Astro](https://github.com/withastro/astro) builds your static Astro project for [GitHub Pages](https://pages.github.com/). 4 | 5 | For more information, please see our complete deployment guide—[Deploy your Astro Site to GitHub Pages](https://docs.astro.build/en/guides/deploy/github/). 6 | 7 | ## Usage 8 | 9 | > **Note**: Want to get started even faster? Create a repository from our official [GitHub Pages template](https://github.com/withastro/github-pages)! 10 | 11 | ### Inputs 12 | 13 | - `path` - Optional: the root location of your Astro project inside the repository. 14 | - `node-version` - Optional: the specific version of Node that should be used to build your site. Defaults to `22`. 15 | - `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 `npm@18.14.1`, `pnpm@8`, or `bun@latest`. If not provided, version will default to `latest`. 16 | 17 | ### Example workflow: 18 | 19 | #### Build and Deploy to GitHub Pages 20 | 21 | Create a file at `.github/workflows/deploy.yml` with the following content. 22 | 23 | ```yml 24 | name: Deploy to GitHub Pages 25 | 26 | on: 27 | # Trigger the workflow every time you push to the `main` branch 28 | # Using a different branch name? Replace `main` with your branch’s name 29 | push: 30 | branches: [main] 31 | # Allows you to run this workflow manually from the Actions tab on GitHub. 32 | workflow_dispatch: 33 | 34 | # Allow this job to clone the repo and create a page deployment 35 | permissions: 36 | contents: read 37 | pages: write 38 | id-token: write 39 | 40 | jobs: 41 | build: 42 | runs-on: ubuntu-latest 43 | steps: 44 | - name: Checkout your repository using git 45 | uses: actions/checkout@v4 46 | - name: Install, build, and upload your site output 47 | uses: withastro/action@v4 48 | # with: 49 | # path: . # The root location of your Astro project inside the repository. (optional) 50 | # node-version: 22 # The specific version of Node that should be used to build your site. Defaults to 22. (optional) 51 | # 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) 52 | 53 | deploy: 54 | needs: build 55 | runs-on: ubuntu-latest 56 | environment: 57 | name: github-pages 58 | url: ${{ steps.deployment.outputs.page_url }} 59 | steps: 60 | - name: Deploy to GitHub Pages 61 | id: deployment 62 | uses: actions/deploy-pages@v4 63 | ``` 64 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: "Astro Deploy" 2 | description: "A composite action that prepares your Astro site to be deployed to GitHub Pages" 3 | branding: 4 | icon: "arrow-up-right" 5 | color: "purple" 6 | inputs: 7 | node-version: 8 | description: "The node version to use" 9 | required: false 10 | default: "22" 11 | package-manager: 12 | description: "You may specify your preferred package manager (one of `npm | yarn | pnpm | bun` and an optional `@` tag). Otherwise, the package manager will be automatically detected." 13 | required: false 14 | default: "" 15 | path: 16 | description: "Path of the directory containing your site" 17 | required: false 18 | default: "." 19 | 20 | runs: 21 | using: composite 22 | steps: 23 | - name: Check lockfiles 24 | shell: "bash" 25 | working-directory: ${{ inputs.path }} 26 | env: 27 | INPUT_PM: ${{ inputs.package-manager }} 28 | run: | 29 | len=`echo $INPUT_PM | wc -c` 30 | if [ $len -gt 1 ]; then 31 | PACKAGE_MANAGER=$(echo "$INPUT_PM" | grep -o '^[^@]*') 32 | VERSION=$(echo "$INPUT_PM" | { grep -o '@.*' || true; } | sed 's/^@//') 33 | # Set default VERSION if not provided 34 | if [ -z "$VERSION" ]; then 35 | VERSION="latest" 36 | fi 37 | echo "PACKAGE_MANAGER=$PACKAGE_MANAGER" >> $GITHUB_ENV 38 | elif [ $(find "." -maxdepth 1 -name "pnpm-lock.yaml") ]; then 39 | echo "PACKAGE_MANAGER=pnpm" >> $GITHUB_ENV 40 | echo "LOCKFILE=pnpm-lock.yaml" >> $GITHUB_ENV 41 | elif [ $(find "." -maxdepth 1 -name "yarn.lock") ]; then 42 | echo "PACKAGE_MANAGER=yarn" >> $GITHUB_ENV 43 | echo "LOCKFILE=yarn.lock" >> $GITHUB_ENV 44 | elif [ $(find "." -maxdepth 1 -name "package-lock.json") ]; then 45 | VERSION="latest" 46 | echo "PACKAGE_MANAGER=npm" >> $GITHUB_ENV 47 | echo "LOCKFILE=package-lock.json" >> $GITHUB_ENV 48 | elif [ $(find "." -maxdepth 1 -name "bun.lock") ]; then 49 | VERSION="latest" 50 | echo "PACKAGE_MANAGER=bun" >> $GITHUB_ENV 51 | echo "LOCKFILE=bun.lock" >> $GITHUB_ENV 52 | elif [ $(find "." -maxdepth 1 -name "bun.lockb") ]; then 53 | VERSION="latest" 54 | echo "PACKAGE_MANAGER=bun" >> $GITHUB_ENV 55 | echo "LOCKFILE=bun.lockb" >> $GITHUB_ENV 56 | else 57 | echo "No lockfile found. 58 | Please specify your preferred \"package-manager\" in the action configuration." 59 | exit 1 60 | fi 61 | echo "VERSION=$VERSION" >> $GITHUB_ENV 62 | - name: Setup PNPM 63 | if: ${{ env.PACKAGE_MANAGER == 'pnpm' }} 64 | uses: pnpm/action-setup@v4 65 | with: 66 | version: ${{ env.VERSION }} 67 | package_json_file: "${{ inputs.path }}/package.json" 68 | 69 | - name: Setup Bun 70 | if: ${{ env.PACKAGE_MANAGER == 'bun' }} 71 | uses: oven-sh/setup-bun@v2 72 | with: 73 | bun-version: ${{ env.VERSION }} 74 | 75 | - name: Setup Node 76 | uses: actions/setup-node@v4 77 | if: ${{ env.PACKAGE_MANAGER != 'bun' }} 78 | with: 79 | node-version: ${{ inputs.node-version }} 80 | cache: ${{ env.PACKAGE_MANAGER }} 81 | cache-dependency-path: "${{ inputs.path }}/${{ env.LOCKFILE }}" 82 | 83 | - name: Setup Node (Bun) 84 | uses: actions/setup-node@v4 85 | if: ${{ env.PACKAGE_MANAGER == 'bun' }} 86 | with: 87 | node-version: ${{ inputs.node-version }} 88 | 89 | - name: Install 90 | shell: "bash" 91 | working-directory: ${{ inputs.path }} 92 | run: $PACKAGE_MANAGER install 93 | 94 | - name: Build 95 | shell: "bash" 96 | working-directory: ${{ inputs.path }} 97 | run: $PACKAGE_MANAGER run build 98 | 99 | - name: Upload Pages Artifact 100 | uses: actions/upload-pages-artifact@v3 101 | with: 102 | path: "${{ inputs.path }}/dist/" 103 | --------------------------------------------------------------------------------