Skip to content

Commit

Permalink
PREview update for improved stability (#10)
Browse files Browse the repository at this point in the history
* Use a checksum rather than branch name to avoid invalid char failures

Signed-off-by: Ben Rockwood <[email protected]>

* DRY: Unify data creation

Signed-off-by: Ben Rockwood <[email protected]>

* Missed a reference to remove

Signed-off-by: Ben Rockwood <[email protected]>

* Missed a pr continue-on-error

Signed-off-by: Ben Rockwood <[email protected]>

* Use env rather than steps.output

Signed-off-by: Ben Rockwood <[email protected]>

* Reusable steps require checkout

Signed-off-by: Ben Rockwood <[email protected]>

---------

Signed-off-by: Ben Rockwood <[email protected]>
  • Loading branch information
benr authored Mar 1, 2024
1 parent f465fa0 commit 70f6394
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 59 deletions.
10 changes: 1 addition & 9 deletions .github/actions/PREview-data/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,10 @@ outputs:
runs:
using: "composite"
steps:
- name: Determine branch shortname, bucket name and URL.
id: data
shell: bash
run: |
BRANCH=`echo ${GITHUB_HEAD_REF} | sed 's/.*\///'`
echo "::set-output name=branch::${BRANCH}"
echo "::set-output name=bucket::mondoo-pre-docs-${BRANCH}/docs"
echo "::set-output name=url::https://mondoo-pre-docs-${BRANCH}.storage.googleapis.com/docs/index.html"
- name: Determine branch shortname and bucket name
shell: bash
run: |
BRANCH=`echo ${GITHUB_HEAD_REF} | sed 's/.*\///'`
BRANCH=`echo ${GITHUB_HEAD_REF} | cksum | cut -d" " -f1` # Use checksum of branch name to avoid invalid bucket names
echo BRANCH=${BRANCH} >> $GITHUB_ENV
echo BUCKET=mondoo-pre-docs-${BRANCH} >> $GITHUB_ENV
echo URL=https://mondoo-pre-docs-${BRANCH}.storage.googleapis.com/docs/index.html >> $GITHUB_ENV
Expand Down
30 changes: 7 additions & 23 deletions .github/workflows/PREview-create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,32 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
allow-repeats: true

data:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.data.outputs.branch }}
bucket: ${{ steps.data.outputs.bucket }}
url: ${{ steps.data.outputs.url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Determine branch shortname, bucket name and URL.
id: data
shell: bash
run: |
BRANCH=`echo ${GITHUB_HEAD_REF} | sed 's/.*\///'`
echo "::set-output name=branch::${BRANCH}"
echo "::set-output name=bucket::mondoo-pre-docs-${BRANCH}/docs"
echo "::set-output name=url::https://mondoo-pre-docs-${BRANCH}.storage.googleapis.com/docs/index.html"
env
build:
uses: ./.github/workflows/_build.yaml
with:
output_dir: build
secrets: inherit

deploy-update:
needs: [data, build]
needs: [build]
uses: ./.github/workflows/_deploy.yaml
with:
src_dir: build
bucket: ${{ needs.data.outputs.bucket }}
secrets: inherit

notify:
runs-on: ubuntu-latest
needs: [deploy-update, data]
needs: [deploy-update]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Obtain Bucket Name
uses: ./.github/actions/PREview-data
- uses: mshick/add-pr-comment@v2
if: success()
continue-on-error: true
with:
message: |
**PREview has been updated at ${{ needs.data.outputs.url }}**
**PREview has been updated at ${{ env.URL }}**
repo-token: ${{ secrets.GITHUB_TOKEN }}
allow-repeats: true
1 change: 1 addition & 0 deletions .github/workflows/PREview-delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- uses: mshick/add-pr-comment@v2
continue-on-error: true
with:
message: |
**Cleaning up PREview environment...**
Expand Down
29 changes: 7 additions & 22 deletions .github/workflows/PREview-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,32 @@ on:
types: [synchronize]

jobs:
data:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.data.outputs.branch }}
bucket: ${{ steps.data.outputs.bucket }}
url: ${{ steps.data.outputs.url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Determine branch shortname, bucket name and URL.
id: data
shell: bash
run: |
BRANCH=`echo ${GITHUB_HEAD_REF} | sed 's/.*\///'`
echo "::set-output name=branch::${BRANCH}"
echo "::set-output name=bucket::mondoo-pre-docs-${BRANCH}/docs"
echo "::set-output name=url::https://mondoo-pre-docs-${BRANCH}.storage.googleapis.com/docs/index.html"
build:
uses: ./.github/workflows/_build.yaml
with:
output_dir: build
secrets: inherit

deploy-update:
needs: [data, build]
needs: [build]
uses: ./.github/workflows/_deploy.yaml
with:
src_dir: build
bucket: ${{ needs.data.outputs.bucket }}
secrets: inherit

notify:
runs-on: ubuntu-latest
needs: [deploy-update, data]
needs: [deploy-update]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Obtain URL
uses: ./.github/actions/PREview-data
- uses: mshick/add-pr-comment@v2
if: success()
continue-on-error: true
with:
message: |
**PREview has been updated at ${{ needs.data.outputs.url }}**
**PREview has been updated at ${{ env.URL }}**
repo-token: ${{ secrets.GITHUB_TOKEN }}
allow-repeats: true
8 changes: 3 additions & 5 deletions .github/workflows/_deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ on:
default: "build"
required: false
type: string
bucket:
description: "The GCS Bucket to write to"
required: true
type: string

jobs:
deploy:
Expand All @@ -30,5 +26,7 @@ jobs:
credentials_json: "${{ secrets.GCP_SERVICE_ACCOUNT }}"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v2"
- name: Obtain Bucket Name
uses: ./.github/actions/PREview-data
- name: Upload static content to buckets
run: gsutil -m -h "Cache-control:public, max-age=60" rsync -r -c -C -d ${{ inputs.src_dir }}/ gs://${{ inputs.bucket }}
run: gsutil -m -h "Cache-control:public, max-age=60" rsync -r -c -C -d ${{ inputs.src_dir }}/ gs://${BUCKET}

0 comments on commit 70f6394

Please sign in to comment.