Add a step to cancel previous workflows #32
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
name: Build and Deploy Astro | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
repository_dispatch: | |
types: [build-trigger] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js current | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .nvmrc | |
- name: Install dependencies & build | |
run: | | |
npm install --legacy-peer-deps | |
npm run build | |
- name: Cancel Previous Deployments | |
id: cancel_previous_deployments | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const deployments = await github.repos.listDeployments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
const inProgressDeployments = deployments.data.filter(deployment => deployment.status === 'in_progress'); | |
for (const deployment of inProgressDeployments) { | |
await github.repos.deleteDeployment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
deployment_id: deployment.id | |
}); | |
} | |
- name: Deploy | |
uses: peaceiris/actions-gh-pages@v4 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
publish_dir: dist | |
# publish_branch is the branch in the repository. | |
# this is where you need to point GitHub pages | |
publish_branch: gh-pages |