Skip to content

Modified get-posts to ignore null entries. #151

Modified get-posts to ignore null entries.

Modified get-posts to ignore null entries. #151

name: Deploy PR Preview cannabis.ca.gov
# site: https://[branch-name].pr.cannabis.ca.gov
# s3 bucket http://pr.cannabis.ca.gov.s3-website-us-west-1.amazonaws.com/
# editor: https://api.cannabis.ca.gov
on:
pull_request:
types:
- opened
- synchronize
- ready_for_review
- reopened
jobs:
build_deploy:
runs-on: ubuntu-20.04
steps:
- uses: n1hility/cancel-previous-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@master
- name: Use Node.js 18.x
uses: actions/setup-node@v1
with:
node-version: 18.16.0
- name: Get branch name (merge)
if: github.event_name != 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
- name: Get branch name (pull request)
if: github.event_name == 'pull_request'
shell: bash
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV
- name: Escape branch name for URL
shell: bash
run: echo "URLSAFE_BRANCH_NAME=$(echo ${BRANCH_NAME} | tr '[:upper:]' '[:lower:]' | sed 's|[^A-Za-z0-9-]|-|g' | sed -E 's|-*([A-Za-z0-9]*.*[A-Za-z0-9]+)-*|\1|')" >> $GITHUB_ENV
- name: Report escaped branch name
shell: bash
run: echo ${URLSAFE_BRANCH_NAME}
- name: Build 11ty
run: |
mkdir dist
npm ci --legacy-peer-deps
SITE_ENV=production DOMAIN=${URLSAFE_BRANCH_NAME}.pr.cannabis.ca.gov npm run build
- name: Write robots.txt
run: |
echo 'User-agent: *' > docs/robots.txt
echo 'Disallow: /' >> docs/robots.txt
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@master
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-west-1
# jbum added exclude
- name: Deploy to S3
run: aws s3 sync --follow-symlinks --delete ./docs s3://pr.cannabis.ca.gov/pr/${URLSAFE_BRANCH_NAME} --exclude 'wp-content/uploads/*'
- name: Invalidate CloudFront cache
run: aws cloudfront create-invalidation --distribution-id ELR9BZ6ZDNOSW --paths "/*"
- name: Post URL to PR
uses: mshick/add-pr-comment@v1
with:
message: |
Preview site available at [${{ env.URLSAFE_BRANCH_NAME }}.pr.cannabis.ca.gov](https://${{ env.URLSAFE_BRANCH_NAME }}.pr.cannabis.ca.gov/).
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: 'github-actions[bot]'
allow-repeats: false