diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5be4dd9..4b0d836 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,8 +1,12 @@ name: Deploy -# Manual only. Run it from the Actions tab when you want the site published: "web" uploads the -# site, "full" also applies infrastructure changes. +# Pushes to main deploy automatically: "full" when the infrastructure, deploy script, dependencies +# or workflows changed, otherwise "web" (just upload the site). Run it by hand from the Actions tab +# to pick either one. on: + push: + branches: [main] + paths-ignore: ['**.md'] workflow_dispatch: inputs: target: @@ -27,8 +31,28 @@ jobs: steps: - uses: actions/checkout@v4 with: + fetch-depth: 0 # to diff against the previous push persist-credentials: false + - name: Pick full or web deploy + id: target + env: + EVENT: ${{ github.event_name }} + INPUT: ${{ inputs.target }} + BEFORE: ${{ github.event.before }} + run: | + if [ "$EVENT" = workflow_dispatch ]; then + target="$INPUT" + elif [ -z "$BEFORE" ] || ! git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then + target=full # first push, or history we can't diff + elif git diff --name-only "$BEFORE" "$GITHUB_SHA" | grep -qE '^infra/|^scripts/deploy.mjs$|^cdk.json$|^package.json$|^yarn.lock$|^.github/'; then + target=full + else + target=web + fi + echo "target=$target" >> "$GITHUB_OUTPUT" + echo "### Deploying: $target" >> "$GITHUB_STEP_SUMMARY" + - uses: actions/setup-node@v4 with: node-version-file: .nvmrc @@ -58,4 +82,4 @@ jobs: - run: node scripts/deploy.mjs "$TARGET" env: - TARGET: ${{ inputs.target }} + TARGET: ${{ steps.target.outputs.target }} diff --git a/README.md b/README.md index 7271877..56188b4 100644 --- a/README.md +++ b/README.md @@ -112,4 +112,4 @@ Both outputs are committed, so a deploy does not need the mods or the game. ## Deploy -Deployed to AWS with CDK. Publish by running the Deploy workflow from the Actions tab. +Deployed to AWS with CDK. Pushes to `main` publish automatically, and the Deploy workflow can also be run from the Actions tab.