|
| 1 | +name: Cortex Docs |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - dev |
| 7 | + pull_request: |
| 8 | + # Review gh actions docs if you want to further define triggers, paths, etc |
| 9 | + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on |
| 10 | + schedule: |
| 11 | + - cron: "0 22 * * 1,2,3,4,5,6" |
| 12 | + |
| 13 | +jobs: |
| 14 | + deploy: |
| 15 | + name: Deploy to Cloudflare Pages |
| 16 | + env: |
| 17 | + CLOUDFLARE_PROJECT_NAME: cortex-docs |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + deployments: write |
| 22 | + pull-requests: write |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v3 |
| 25 | + - uses: actions/setup-node@v3 |
| 26 | + with: |
| 27 | + node-version: 18 |
| 28 | + |
| 29 | + - name: Install jq |
| 30 | + uses: dcarbone/install-jq-action@v2.0.1 |
| 31 | + |
| 32 | + - name: Fill env vars |
| 33 | + working-directory: docs |
| 34 | + continue-on-error: true |
| 35 | + run: | |
| 36 | + env_example_file=".env.example" |
| 37 | + touch .env |
| 38 | + while IFS= read -r line || [[ -n "$line" ]]; do |
| 39 | + if [[ "$line" == *"="* ]]; then |
| 40 | + var_name=$(echo $line | cut -d '=' -f 1) |
| 41 | + echo $var_name |
| 42 | + var_value="$(jq -r --arg key "$var_name" '.[$key]' <<< "$SECRETS")" |
| 43 | + echo "$var_name=$var_value" >> .env |
| 44 | + fi |
| 45 | + done < "$env_example_file" |
| 46 | + env: |
| 47 | + SECRETS: "${{ toJson(secrets) }}" |
| 48 | + |
| 49 | + - name: Install dependencies |
| 50 | + working-directory: docs |
| 51 | + run: yarn install |
| 52 | + - name: Build website |
| 53 | + working-directory: docs |
| 54 | + run: export NODE_ENV=production && yarn build |
| 55 | + |
| 56 | + - name: Copy redirect file |
| 57 | + working-directory: docs |
| 58 | + continue-on-error: true |
| 59 | + run: cp _redirects build/_redirects |
| 60 | + |
| 61 | + - name: Publish to Cloudflare Pages PR Preview and Staging |
| 62 | + if: github.event_name == 'pull_request' |
| 63 | + uses: cloudflare/pages-action@v1 |
| 64 | + with: |
| 65 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 66 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 67 | + projectName: ${{ env.CLOUDFLARE_PROJECT_NAME }} |
| 68 | + directory: ./docs/build |
| 69 | + # Optional: Enable this if you want to have GitHub Deployments triggered |
| 70 | + gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + id: deployCloudflarePages |
| 72 | + |
| 73 | + - uses: mshick/add-pr-comment@v2 |
| 74 | + if: github.event_name == 'pull_request' |
| 75 | + with: |
| 76 | + message: | |
| 77 | + Preview URL: ${{ steps.deployCloudflarePages.outputs.url }} |
| 78 | +
|
| 79 | + - name: Publish to Cloudflare Pages Production |
| 80 | + if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/dev' && github.event.pull_request.head.repo.full_name != github.repository |
| 81 | + uses: cloudflare/pages-action@v1 |
| 82 | + with: |
| 83 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 84 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 85 | + projectName: ${{ env.CLOUDFLARE_PROJECT_NAME }} |
| 86 | + directory: ./docs/build |
| 87 | + branch: dev |
| 88 | + # Optional: Enable this if you want to have GitHub Deployments triggered |
| 89 | + gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments