diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index d1e78fc08..359133e97 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -57,12 +57,68 @@ jobs: - name: Clean previous deployment of this branch run: aws s3 rm s3://wiris-integrations-staging-html/${{ matrix.branch }} --recursive + deploy-staging-common: + name: Deploy the staging environment (common elements) + runs-on: ubuntu-latest + needs: + - prepare + - clean-staging + strategy: + fail-fast: true + matrix: + branch: ${{ fromJson(needs.prepare.outputs.branches) }} + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + + - name: Checkout + uses: actions/checkout@v2 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_STAGING }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGING }} + aws-region: eu-west-2 + + - name: Upload the common files + run: | + # Replace token %BRANCH% with branch name in staging/branch + find staging/branch -type f -exec sed -i 's/%BRANCH%/${{ matrix.branch }}/g' {} \; + aws s3 cp staging/branch s3://wiris-integrations-staging-html/${{ matrix.branch }} --recursive + aws s3 cp staging/root s3://wiris-integrations-staging-html/ --recursive + + - name: Add branch to the list of branches + run: | + BRANCHES=branches + + # Check if the remote list of branches exists + aws s3api head-object --bucket wiris-integrations-staging-html --key branches || NOT_EXIST=true + if [ $NOT_EXIST ]; then + # Create empty list of branches + touch "${BRANCHES}" + else + # Copy list of branches from S3 to local + aws s3 cp "s3://wiris-integrations-staging-html/${BRANCHES}" "${BRANCHES}" + fi + + # Check if branch name is already in the file + if ! grep -q -F "${{ matrix.branch }}" "${BRANCHES}"; then + # Update local list of branches + echo ${{ matrix.branch }} >> "${BRANCHES}" + # Upload updated file + aws s3 cp "${BRANCHES}" "s3://wiris-integrations-staging-html/${BRANCHES}" + fi + deploy-staging: name: Deploy the staging environment runs-on: ubuntu-latest needs: - prepare - clean-staging + - deploy-staging-common strategy: fail-fast: false matrix: @@ -95,7 +151,7 @@ jobs: aws-region: eu-west-2 - name: Build the demos - + run: | npm set "//registry.npmjs.org/:_authToken" ${{ secrets.NPM_TOKEN }} yarn @@ -150,6 +206,7 @@ jobs: needs: - prepare - clean-staging + - deploy-staging-common - deploy-staging steps: diff --git a/.github/workflows/dismantle-staging.yml b/.github/workflows/dismantle-staging.yml index 531112054..eb0454f5d 100644 --- a/.github/workflows/dismantle-staging.yml +++ b/.github/workflows/dismantle-staging.yml @@ -32,5 +32,18 @@ jobs: run: | aws s3 rm s3://wiris-integrations-staging-html/${{ github.event.ref }} --recursive + - name: Remove branch from the list of branches + run: | + BRANCHES=branches + # Copy list of branches from S3 to local + aws s3 cp "s3://wiris-integrations-staging-html/${BRANCHES}" "${BRANCHES}" + # Check if branch name is in the file + if grep -q -F "${{ matrix.branch }}" "${BRANCHES}"; then + # Update local list of branches + sed '/^${{ github.event.ref }}$/d' "${BRANCHES}" + # Upload updated file + aws s3 cp "${BRANCHES}" "s3://wiris-integrations-staging-html/${BRANCHES}" + fi + - name: Invalidate CloudFront cache run: aws cloudfront create-invalidation --distribution-id $(aws cloudfront list-distributions --query "DistributionList.Items[?Aliases.Items!=null] | [?contains(Aliases.Items, 'integrations.wiris.kitchen')].Id | [0]" --output text) --paths '/*' diff --git a/staging/branch/angular/index.html b/staging/branch/angular/index.html new file mode 100644 index 000000000..1ec17dd9d --- /dev/null +++ b/staging/branch/angular/index.html @@ -0,0 +1,23 @@ + + + + + Demos %BRANCH% / Angular + + + + Demos %BRANCH% +

Demos %BRANCH% / Angular

+ + + diff --git a/staging/branch/html/index.html b/staging/branch/html/index.html new file mode 100644 index 000000000..1df73b7f9 --- /dev/null +++ b/staging/branch/html/index.html @@ -0,0 +1,25 @@ + + + + + Demos %BRANCH% / HTML + + + + Demos %BRANCH% +

Demos %BRANCH% / HTML

+ + + diff --git a/staging/branch/index.html b/staging/branch/index.html new file mode 100644 index 000000000..9a17f5961 --- /dev/null +++ b/staging/branch/index.html @@ -0,0 +1,43 @@ + + + + + Demos %BRANCH% + + + + All demos +

Demos %BRANCH%

+ + + diff --git a/staging/branch/react/index.html b/staging/branch/react/index.html new file mode 100644 index 000000000..944d2d4ea --- /dev/null +++ b/staging/branch/react/index.html @@ -0,0 +1,23 @@ + + + + + Demos %BRANCH% / React + + + + Demos %BRANCH% +

Demos %BRANCH% / React

+ + + diff --git a/staging/root/index.html b/staging/root/index.html new file mode 100644 index 000000000..5dab0159c --- /dev/null +++ b/staging/root/index.html @@ -0,0 +1,29 @@ + + + + + All demos + + + + +

All demos

+ + + diff --git a/staging/root/styles.css b/staging/root/styles.css new file mode 100644 index 000000000..b57952839 --- /dev/null +++ b/staging/root/styles.css @@ -0,0 +1,15 @@ +body { + font-family: sans-serif; +} + +h2 { + margin: 5px; +} + +section { + background-color: #7eff83;; + border: 1px solid #7eff83;; + border-radius: 15px; + padding: 10px; + margin: 5px; +}