Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PREview environments should use a unique string #9

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 6 additions & 23 deletions .github/workflows/PREview-create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,48 +39,31 @@ 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: Obtain Bucket Name
id: data
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 ${{ steps.data.outputs.url }}**
repo-token: ${{ secrets.GITHUB_TOKEN }}
allow-repeats: true
28 changes: 6 additions & 22 deletions .github/workflows/PREview-update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,31 @@ 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: Obtain URL
id: data
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 ${{ steps.data.outputs.url }}**
repo-token: ${{ secrets.GITHUB_TOKEN }}
allow-repeats: true
9 changes: 4 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,8 @@ jobs:
credentials_json: "${{ secrets.GCP_SERVICE_ACCOUNT }}"
- name: "Set up Cloud SDK"
uses: "google-github-actions/setup-gcloud@v2"
- name: Obtain Bucket Name
id: data
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://${{ steps.data.outputs.bucket }}
Loading