chore: update edgepkgs #118
Workflow file for this run
This file contains hidden or 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: terraform | |
| on: | |
| pull_request: | |
| branches: | |
| - main | |
| paths: | |
| - 'infra/**' | |
| - '.github/workflows/terraform.yml' | |
| - 'flake.lock' | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'infra/**' | |
| - '.github/workflows/terraform.yml' | |
| - 'flake.lock' | |
| permissions: | |
| id-token: write | |
| contents: read | |
| pull-requests: write | |
| jobs: | |
| detect: | |
| runs-on: ubuntu-slim | |
| timeout-minutes: 5 | |
| outputs: | |
| directories: ${{ steps.build-matrix.outputs.directories }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1 | |
| id: filter | |
| with: | |
| filters: | | |
| github: | |
| - 'infra/services/github/**' | |
| cloudflare: | |
| - 'infra/global/domains/natsukium-com/**' | |
| shared: | |
| - 'flake.lock' | |
| - '.github/workflows/terraform.yml' | |
| - id: build-matrix | |
| run: | | |
| directories='[]' | |
| if [[ "${{ steps.filter.outputs.shared }}" == "true" ]]; then | |
| directories='["infra/services/github","infra/global/domains/natsukium-com"]' | |
| else | |
| dirs=() | |
| if [[ "${{ steps.filter.outputs.github }}" == "true" ]]; then | |
| dirs+=("infra/services/github") | |
| fi | |
| if [[ "${{ steps.filter.outputs.cloudflare }}" == "true" ]]; then | |
| dirs+=("infra/global/domains/natsukium-com") | |
| fi | |
| directories=$(printf '%s\n' "${dirs[@]}" | jq -R . | jq -sc .) | |
| fi | |
| echo "directories=$directories" >> "$GITHUB_OUTPUT" | |
| terraform: | |
| needs: detect | |
| if: needs.detect.outputs.directories != '[]' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| strategy: | |
| matrix: | |
| directory: ${{ fromJson(needs.detect.outputs.directories) }} | |
| env: | |
| SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }} | |
| defaults: | |
| run: | |
| working-directory: ${{ matrix.directory }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: ./.github/actions/setup-nix | |
| with: | |
| authToken: ${{ secrets.CACHIX_AUTH_TOKEN }} | |
| - uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0 | |
| with: | |
| role-to-assume: ${{ vars.AWS_PLAN_ROLE_ARN }} | |
| aws-region: us-east-2 | |
| - name: Terraform Init | |
| run: nix develop -c terraform init | |
| - name: Terraform Format | |
| run: nix develop -c terraform fmt -check | |
| - name: Terraform Plan | |
| id: plan | |
| run: | | |
| set +e | |
| nix develop -c terraform plan -no-color -lock=false -out=tfplan > plan.txt 2>&1 | |
| exit_code=$? | |
| { | |
| echo "stdout<<EOF" | |
| sed -n '/Terraform used the selected providers/,$ p' plan.txt || cat plan.txt | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| echo "has_changes=$( ! grep -q 'No changes' plan.txt && echo true || echo false)" >> "$GITHUB_OUTPUT" | |
| exit $exit_code | |
| continue-on-error: true | |
| - name: Comment PR | |
| if: github.event_name == 'pull_request' && steps.plan.outputs.has_changes == 'true' | |
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 | |
| with: | |
| script: | | |
| const output = `#### Terraform Plan: \`${{ matrix.directory }}\` 📖 | |
| \`\`\` | |
| ${{ steps.plan.outputs.stdout }} | |
| \`\`\` | |
| `; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: output, | |
| }); | |
| - name: Terraform Plan Status | |
| if: steps.plan.outcome == 'failure' | |
| run: exit 1 | |
| - name: Configure AWS Credentials for Apply | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0 | |
| with: | |
| role-to-assume: ${{ vars.AWS_APPLY_ROLE_ARN }} | |
| aws-region: us-east-2 | |
| - name: Terraform Apply | |
| if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
| run: nix develop -c terraform apply tfplan |