add clone step #20
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: deploy-preview | ||
on: | ||
workflow_call: | ||
inputs: | ||
sha: | ||
required: true | ||
type: string | ||
branch: | ||
required: true | ||
type: string | ||
event_number: | ||
required: true | ||
type: string | ||
title: | ||
required: true | ||
type: string | ||
repo: | ||
required: true | ||
type: string | ||
source_directory: | ||
default: docs/sources | ||
type: string | ||
website_directory: | ||
required: true | ||
type: string | ||
relative_prefix: | ||
required: true | ||
type: string | ||
env: | ||
CLOUD_RUN_REGION: us-south1 | ||
permissions: | ||
contents: read | ||
id-token: write | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
jobs: | ||
deploy-preview: | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build website | ||
shell: bash | ||
run: | | ||
mkdir -p ${PWD}/dist | ||
docker run -v ${PWD}/dist:/hugo/dist -v "${PWD}/${{ inputs.source_directory }}:/hugo/${{ inputs.website_directory }}" --rm grafana/docs-base:latest /bin/bash -c 'hugo --environment=docs --destination=dist/ --baseURL= --minify' | ||
- uses: google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f # v2.1.7 | ||
id: gcloud-auth | ||
with: | ||
token_format: access_token | ||
workload_identity_provider: "projects/304398677251/locations/global/workloadIdentityPools/github/providers/github-provider" | ||
service_account: github-docs-deploy-previews@grafanalabs-workload-identity.iam.gserviceaccount.com | ||
create_credentials_file: false | ||
- name: Login to GAR | ||
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 | ||
with: | ||
registry: us-docker.pkg.dev | ||
username: oauth2accesstoken | ||
password: ${{ steps.gcloud-auth.outputs.access_token }} | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 | ||
with: | ||
images: "us-docker.pkg.dev/grafanalabs-dev/docker-docs-previews-dev/${{ inputs.repo }}" | ||
tags: |- | ||
"${{ inputs.sha }}" | ||
"${{ inputs.event_number }}" | ||
# get the Dockerfile and nginx conf | ||
- name: Sparse checkout | ||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
if: github.event.action != 'closed' | ||
with: | ||
repository: "grafana/writers-toolkit" | ||
ref: "robbymilo/deploy-preview" | ||
sparse-checkout: | | ||
deploy-preview | ||
- name: test | ||
run: | | ||
ls -al | ||
ls -al deploy-preview | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1 | ||
with: | ||
driver: docker-container | ||
- name: Build the container | ||
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0 | ||
id: build | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
file: ./deploy-preview/Dockerfile | ||
- uses: "google-github-actions/[email protected]" | ||
id: gcloud-auth-cloud-run | ||
with: | ||
workload_identity_provider: "projects/304398677251/locations/global/workloadIdentityPools/github/providers/github-provider" | ||
service_account: "github-docs-cloud-run-dev@grafanalabs-workload-identity.iam.gserviceaccount.com" | ||
- name: Deploy to Cloud Run | ||
uses: "google-github-actions/[email protected]" | ||
if: github.event.action != 'closed' | ||
id: deploy | ||
with: | ||
image: us-docker.pkg.dev/grafanalabs-dev/docker-docs-previews-dev/${{ inputs.repo }}:${{ inputs.sha }} | ||
service: deploy-preview-${{ inputs.repo }}-${{ inputs.event_number }} | ||
project_id: grafanalabs-dev | ||
region: us-south1 | ||
flags: --port=80 --ingress=all --allow-unauthenticated | ||
- name: Send commit status | ||
uses: ouzi-dev/commit-status-updater@v2 | ||
if: github.event.action != 'closed' | ||
with: | ||
name: deploy_preview | ||
status: "${{ job.status }}" | ||
url: "${{ steps.deploy.outputs.url }}${{ inputs.relative_prefix }}" | ||
description: "Public deploy preview" |