Create README_.md #1
Workflow file for this run
This file contains 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: TEST-ENV-DEPLOYMENT | |
# Build and deploy test instance for every pull request | |
on: | |
pull_request: | |
# trigger on "edited" to update instance when configuration changes in PR description | |
types: [opened, reopened, synchronize] | |
branches: ["*"] | |
jobs: | |
deploy: | |
if: github.event.pull_request.head.repo.full_name == 'mirumee/saleor-storefront' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: rlespinasse/[email protected] | |
- name: Start deployment | |
uses: bobheadxi/[email protected] | |
id: deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: ${{ env.GITHUB_HEAD_REF_SLUG_URL }} | |
ref: ${{ github.head_ref }} | |
- name: Start storybook deployment | |
uses: bobheadxi/[email protected] | |
id: storybook-deployment | |
with: | |
step: start | |
token: ${{ secrets.GITHUB_TOKEN }} | |
env: storybook ${{ env.GITHUB_HEAD_REF_SLUG_URL }} | |
ref: ${{ github.head_ref }} | |
- name: Cache node modules | |
uses: actions/cache@v2 | |
env: | |
cache-name: cache-node-modules | |
with: | |
path: ~/.npm | |
key: ${{ runner.os }}-qa-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-qa-${{ env.cache-name }}- | |
${{ runner.os }}-qa- | |
${{ runner.os }}- | |
- name: Install deps | |
run: | | |
npm i | |
- name: Get custom API_URI | |
id: api_uri | |
# Search for API_URI in PR description | |
env: | |
pull_request_body: ${{ github.event.pull_request.body }} | |
prefix: API_URI= | |
pattern: (http|https)://[a-zA-Z0-9.-]+/graphql/? | |
run: | | |
echo "::set-output name=custom_api_uri::$(echo $pull_request_body | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1)" | |
- name: Create env file | |
uses: SpicyPizza/create-envfile@v1 | |
with: | |
# Use custom API_URI or the default one | |
envkey_NEXT_PUBLIC_API_URI: ${{ steps.api_uri.outputs.custom_api_uri || secrets.API_URI }} | |
envkey_NEXT_PUBLIC_SALEOR_CHANNEL_SLUG: "default-channel" | |
file_name: .env.local | |
- name: Run build | |
run: | | |
npm run build:export | |
- name: Run build storybook | |
env: | |
NODE_OPTIONS: --max_old_space_size=4096 | |
run: | | |
npm run build-storybook | |
- name: Set domain | |
id: set-domain | |
# Set test instance domain based on branch name slug | |
run: | | |
echo "::set-output name=domain::${{ env.GITHUB_HEAD_REF_SLUG_URL }}.storefront.saleor.rocks" | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_DEFAULT_REGION }} | |
- name: Deploy to S3 | |
run: aws s3 sync ./dist s3://${{ secrets.AWS_TEST_DEPLOYMENT_BUCKET }}/${{ steps.set-domain.outputs.domain }} | |
- name: Invalidate cache | |
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_TEST_CF_DIST_ID }} --paths "/${{ steps.set-domain.outputs.domain }}/*" | |
- name: Update deployment status | |
uses: bobheadxi/[email protected] | |
if: always() | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
env_url: https://${{ steps.set-domain.outputs.domain }}/ | |
deployment_id: ${{ steps.deployment.outputs.deployment_id }} | |
- name: Update storybook deployment status | |
uses: bobheadxi/[email protected] | |
if: always() | |
with: | |
step: finish | |
token: ${{ secrets.GITHUB_TOKEN }} | |
status: ${{ job.status }} | |
env_url: https://${{ steps.set-domain.outputs.domain }}/storybook/index.html | |
deployment_id: ${{ steps.storybook-deployment.outputs.deployment_id }} |