From 1160a1e9b7f22744e031fd72a42baa4669577434 Mon Sep 17 00:00:00 2001 From: Marc Cataford Date: Sat, 17 Jul 2021 12:30:27 -0400 Subject: [PATCH] infra: set up CI (#7) * ci: stub * fix: typo * fix: cache restore * fix: install * fix: typo * ci: caches, build, artifacts * ci: caches, build, artifacts * fix: typo * ci: preview deploy * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * ci: preview deploy output * fix: conds --- .github/workflows/main.yml | 124 +++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..3493399 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,124 @@ +on: + push: + branches: + master + pull_request: + +env: + NODE_VERSION: 16 + +jobs: + setup: + runs-on: ubuntu-latest + name: Setup + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + id: node-setup + with: + node-version: ${{ env.NODE_VERSION }} + - uses: actions/cache@v2 + id: cache-restore + with: + path: | + .yarn + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ env.NODE_VERSION }} + - name: Install dependencies + if: steps.cache-restore.outputs.cache-hit != 'true' + run: yarn + build: + runs-on: ubuntu-latest + name: Build + needs: setup + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + id: node-setup + with: + node-version: ${{ env.NODE_VERSION }} + - name: Yarn cache + uses: actions/cache@v2 + id: yarn-cache-restore + with: + path: | + .yarn + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ env.NODE_VERSION }} + - name: Parcel cache + uses: actions/cache@v2 + id: parcel-cache-restore + with: + path: | + .parcel-cache + key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}-${{ env.NODE_VERSION }}-parcel + - run: | + yarn + yarn build + - name: Build Artifacts + uses: actions/upload-artifact@v2 + with: + name: build-artifacts + path: dist + preview: + runs-on: ubuntu-latest + name: Deploy preview + if: ${{ github.ref != 'refs/head/master' }} + needs: build + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + id: node-setup + with: + node-version: ${{ env.NODE_VERSION }} + - name: Build Artifacts + uses: actions/download-artifact@v2 + with: + name: build-artifacts + path: dist + - name: Netlify CLI setup + run: npm install -g netlify-cli + - name: Deploy + id: preview-deploy + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + run: | + netlify deploy --dir=dist > output.log + echo "::set-output name=draft-url::$(grep 'Website Draft URL' output.log)" + - name: Report + uses: actions/github-script@v2 + env: + DRAFT_URL: ${{ steps.preview-deploy.outputs.draft-url }} + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `:eyes: Branch deployed at ${process.env.DRAFT_URL}` + }) + deploy: + runs-on: ubuntu-latest + name: Deploy + needs: build + if: ${{ github.ref == 'refs/head/master' }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + id: node-setup + with: + node-version: ${{ env.NODE_VERSION }} + - name: Build Artifacts + uses: actions/download-artifact@v2 + with: + name: build-artifacts + path: dist + - name: Netlify CLI setup + run: npm install -g netlify-cli + - name: Deploy + id: preview-deploy + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + run: | + netlify deploy --dir=dist --prod