From 9c47b04341127d0afde8f187976bcea6dd858929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Mi=C4=85cz?= Date: Mon, 6 Jul 2020 20:50:48 +0200 Subject: [PATCH] Setup test environment deployment workflow --- .github/PULL_REQUEST_TEMPLATE.md | 6 +++ .github/workflows/test-env-deploy.yml | 66 +++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 .github/workflows/test-env-deploy.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 7135688da..df5d5c5d0 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -20,3 +20,9 @@ greatly reduce the amount of work needed to review your work. --> 1. [ ] The changes are tested. 1. [ ] Type definitions are up to date. 1. [ ] Changes are mentioned in the changelog. + +### Test environment config + +``` +API_URI=https://master.staging.saleor.rocks/graphql/ +``` diff --git a/.github/workflows/test-env-deploy.yml b/.github/workflows/test-env-deploy.yml new file mode 100644 index 000000000..722956a34 --- /dev/null +++ b/.github/workflows/test-env-deploy.yml @@ -0,0 +1,66 @@ +name: TEST-ENV-DEPLOYMENT + +on: + pull_request: + types: [opened, reopened, edited, synchronize] + branches: ["*"] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + 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 ci + + - name: Set API URI + env: + pull_request_body: ${{ github.event.pull_request.body }} + prefix: API_URI= + pattern: (http|https)://[a-zA-Z0-9.]+/graphql/? + run: | + echo "::set-env name=API_URI::$(echo $pull_request_body | grep -Eo "$prefix$pattern" | sed s/$prefix// | head -n 1)" + + - name: Run build + env: + APP_MOUNT_URI: / + STATIC_URL: / + run: | + npm run build + + - uses: rlespinasse/github-slug-action@master + - name: Set domain + run: | + echo "::set-env name=domain::${{ env.GITHUB_HEAD_REF_SLUG }}.dashboard.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 ./build/dashboard s3://test-envs-stack-dashboards5d35b643-nempmfdd9fv/${{ env.domain }} + + - name: Invalidate cache + run: aws cloudfront create-invalidation --distribution-id E1INMM566C4FJP --paths "/${{ env.domain }}/*" + + - name: Print URL + run: | + echo https://${{ env.domain }}/