4/merge - "" #189
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: Build and Deploy | |
| run-name: ${{ github.ref_name }} - "${{ github.event.head_commit.message }}" | |
| on: | |
| # TODO: other environments? | |
| pull_request: | |
| paths: | |
| - 'generator/**' | |
| - '.github/workflows/build**' | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'generator/**' | |
| - '.github/workflows/build**' | |
| env: | |
| AWS_REGION: "us-east-2" | |
| ACTIONS_STEP_DEBUG: true | |
| TF_VAR_domain: appli.ng | |
| TF_VAR_subdomain: reece | |
| permissions: | |
| id-token: write | |
| contents: read | |
| actions: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| generate-markdown: | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| id-token: write | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| sparse-checkout: | | |
| generator | |
| go.mod | |
| blogPosts | |
| notes | |
| - uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: 'go.mod' | |
| # GitHub token for authentication | |
| token: ${{ github.token }} | |
| cache: false | |
| cache-dependency-path: 'go.sum' | |
| - name: Generate files | |
| run: | | |
| sudo chown -R $USER:$USER ${{ github.workspace }} | |
| mkdir -p ./quartz/content | |
| sudo go run ./generator | |
| sudo chown -R $USER:$USER . | |
| chmod -R 777 ./quartz/content | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: markdownFiles | |
| path: quartz/content | |
| if-no-files-found: error | |
| retention-days: 1 | |
| # The level of compression for Zlib to be applied to the artifact archive. | |
| # The value can range from 0 to 9. | |
| # For large files that are not easily compressed, a value of 0 is recommended for significantly faster uploads. | |
| # Optional. Default is '6' | |
| compression-level: 6 | |
| overwrite: true | |
| # Whether to include hidden files in the provided path in the artifact | |
| # The file contents of any hidden files in the path should be validated before | |
| # enabled this to avoid uploading sensitive information. | |
| # Optional. Default is 'false' | |
| include-hidden-files: false | |
| build-quartz: | |
| needs: [ generate-markdown ] | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| sparse-checkout: | | |
| quartzModified | |
| - name: Clone Quartz 4 | |
| run: git clone https://github.com/jackyzha0/quartz.git | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: install quartz deps | |
| run: npm i | |
| working-directory: quartz | |
| - name: create quartz work area | |
| # Create new quartz, using shortest links (shortest, relative, absolute). -s=dir? | |
| run: npx quartz create -X new -l shortest | |
| working-directory: quartz | |
| - uses: actions/download-artifact@v5 | |
| with: | |
| name: markdownFiles | |
| path: ./quartz/content | |
| - name: set modified quartz files at top level | |
| run: | | |
| rm -f quartz/quartz.layout.ts && mv quartzModified/quartz.layout.ts quartz/quartz.layout.ts | |
| rm -f quartz/quartz.config.ts && mv quartzModified/quartz.config.ts quartz/quartz.config.ts | |
| - name: set modified quartz files | |
| run: | | |
| ( | |
| cd quartzModified/quartz && find . -type f -print0 | |
| ) | while IFS= read -r -d '' file_relative_path; do | |
| clean_path="${file_relative_path#./}" | |
| echo "Replacing: quartz/quartz/$clean_path from quartzModified/quartz/$clean_path" | |
| rm -f quartz/quartz/$clean_path && mv quartzModified/quartz/$clean_path quartz/quartz/$clean_path | |
| done | |
| - name: Build Quartz | |
| run: npx --quiet quartz build | |
| working-directory: ./quartz | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: finalFiles | |
| path: ./quartz/public | |
| if-no-files-found: error | |
| retention-days: 1 | |
| # The level of compression for Zlib to be applied to the artifact archive. | |
| # The value can range from 0 to 9. Default is '6' | |
| compression-level: 6 | |
| overwrite: true | |
| include-hidden-files: false | |
| deploy: | |
| needs: [build-quartz, generate-markdown] | |
| if: | | |
| github.ref == 'refs/heads/main' | |
| && always() && !cancelled() | |
| && (needs.generate-markdown.result == 'success') | |
| && needs.build-quartz.result == 'success' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| actions: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| sparse-checkout: | | |
| terraform | |
| static | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| with: | |
| terraform_version: "1.14.6" | |
| - name: Configure AWS Credentials | |
| uses: aws-actions/[email protected] | |
| with: | |
| role-to-assume: ${{ secrets.AWS_RUNNER_ROLE }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| role-session-name: reeceSubdomainDeployment | |
| - uses: actions/download-artifact@v5 | |
| with: | |
| name: finalFiles | |
| path: terraform/public | |
| # - name: clean out s3 bucket # Do not do this because it is more expensive | |
| # run: aws s3 rm s3://${{ env.TF_VAR_subdomain }}.${{ env.TF_VAR_domain }} --recursive | |
| - name: move static files | |
| run: | | |
| if test -d static; then | |
| if [ -z "$(find ./static -maxdepth 0 -type d -empty)" ]; then | |
| mv -f static/* terraform/public/static/ | |
| fi | |
| fi | |
| # TODO: ONLY REPLACE FILES THAT HAVE CHANGED! | |
| - name: initialize terraform | |
| run: terraform init -backend-config='bucket=${{ vars.TERRAFORM_STATE_BUCKET }}' -backend-config='region=${{ env.AWS_REGION }}' | |
| working-directory: terraform | |
| - name: plan terraform | |
| run: terraform plan -var-file='deploy.tfvars' -var 'cloudflare_api_token=${{secrets.CLOUDFLARE_API_TOKEN}}' -var 'cloudflare_zone_id=${{secrets.CLOUDFLARE_ZONE_ID}}' -var 'aws_region=${{env.AWS_REGION}}' -out=plan.tf | |
| working-directory: terraform | |
| - name: apply terraform | |
| run: terraform apply -auto-approve plan.tf | |
| working-directory: terraform | |
| # env: | |
| # # TODO: set tf verbose if needed | |
| # TF_LOG: TRACE | |
| # - name: plan terraform destroy | |
| # run: terraform plan -destroy -var-file='deploy.tfvars' -var 'cloudflare_api_token=${{secrets.CLOUDFLARE_API_TOKEN}}' -var 'cloudflare_zone_id=${{secrets.CLOUDFLARE_ZONE_ID}}' -var 'aws_region=${{env.AWS_REGION}}' -out=plan.tf | |
| # working-directory: terraform | |
| # - name: apply terraform destroy | |
| # run: terraform apply -auto-approve -destroy plan.tf |