Skip to content

Commit

Permalink
Test with composite action
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
  • Loading branch information
jdbaldry committed Jan 13, 2025
1 parent 8a13f2c commit b887ce8
Showing 2 changed files with 227 additions and 9 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/deploy-pr-preview.yml
Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@ on:
paths:
- "docs/sources/**"

concurrency:
group: ${{ github.workflow }}-${{ inputs.repo }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
deploy-pr-preview:
if: ${{ ! github.event.pull_request.head.repo.fork }}
@@ -20,15 +24,7 @@ jobs:
sparse-checkout-cone-mode: false # exclude root files
sparse-checkout: docs

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
repo: grafana/writers-toolkit
sparse-checkout-cone-mode: false # exclude root files
sparse-checkout: |
.github/workflows/deploy-preview.yml
- uses: ./.github/workflows/deploy-preview.yml
- uses: ./deploy-preview
with:
branch: ${{ github.head_ref }}
event_number: ${{ github.event.number }}
222 changes: 222 additions & 0 deletions deploy-preview/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
name: deploy-preview

inputs:
sha:
required: true
type: string
branch:
required: true
type: string
event_number:
required: true
type: string
title:
required: true
type: string

sources:
description: |
sources is a JSON string describing multiple source mounts.
It replaces the individual inputs used in the previous version of this action.
The structure is an array of objects, each with the following keys:
index_file:
description: Path to index file used to redirect versioned projects. For example, "content/docs/mimir/_index.md".
required: true
type: string
relative_prefix:
description: The URL path prefix for the mount destination. For example, "/docs/mimir/latest/".
required: true
type: string
repo:
description: The Grafana repository name for the source files. For example, "mimir".
required: true
type: string
source_directory:
description: The path to the source files in the repository. For example, "docs/sources".
required: true
type: string
website_directory:
description: The path to mount the documentation in the website content structure. For example, "content/docs/mimir/latest".
required: true
type: string
The following example mounts both the Mimir documentation and the mimir-distributed Helm chart documentation:
[
{
"index_file": true,
"relative_prefix": "/docs/mimir/latest/",
"repo": "mimir",
"source_directory": "docs/sources/mimir",
"website_directory": "content/docs/mimir/latest"
},
{
"index_file": true,
"relative_prefix": "/docs/helm-charts/mimir-distributed/latest/",
"repo": "mimir",
"source_directory": "docs/sources/mimir-distributed",
"website_directory": "content/docs/helm-charts/mimir-distributed/latest"
}
]
type: string


runs:
using: composite
permissions:
contents: read
id-token: write # Fetch Vault secrets.
pull-requests: write # Create or update PR comments.
statuses: write # Update GitHub status check with deploy preview link.
runs-on: ubuntu-latest
steps:
- name: Find comment
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
id: fc
with:
issue-number: ${{ inputs.event_number }}
comment-author: "github-actions[bot]"
body-includes: Deploy preview available

- name: Update comment with in-progress deploy preview
if: steps.fc.outputs.comment-id != '' && (github.event.action == 'opened' || github.event.action == 'synchronize')
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ inputs.event_number }}
edit-mode: append
append-separator: newline
body: |
:building_construction: Updating deploy preview...
- name: Build website
if: github.event.action == 'opened' || github.event.action == 'synchronize'
shell: bash
env:
ACTION_PATH: ${{ github.action_path }}
SOURCES: ${{ inputs.sources }}
run: |
"${ACTION_PATH}/deploy-preview-files/deploy-preview/build.sh"
- name: Print build header value
if: github.event.action == 'opened' || github.event.action == 'synchronize'
shell: bash
env:
SHA: ${{ inputs.sha }}
run: |
printf "%s" "add_header 'Build' '"${SHA}"';" > build.conf
- uses: google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f # v2.1.7
if: github.event.action == 'opened' || github.event.action == 'synchronize'
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
if: github.event.action == 'opened' || github.event.action == 'synchronize'
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
if: github.event.action == 'opened' || github.event.action == 'synchronize'
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 }}"
- name: Set up Docker Buildx
if: github.event.action == 'opened' || github.event.action == 'synchronize'
uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 # v3.7.1
with:
cache-binary: false
driver: docker-container

- name: Build the container
if: github.event.action == 'opened' || github.event.action == 'synchronize'
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
id: build
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
file: ./deploy-preview-files/deploy-preview/Dockerfile

- uses: google-github-actions/auth@8254fb75a33b976a221574d287e93919e6a36f70 # v2.1.6
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/deploy-cloudrun@1ec29da1351112c7904fb60454a55e3e1021a51c # v2.7.2
if: github.event.action == 'opened' || github.event.action == 'synchronize'
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: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@6189d56e4096ee891640bb02ac264be376592d6a # v2.1.2
if: github.event.action == 'closed'
with:
project_id: grafanalabs-dev

- name: Delete deploy preview
if: github.event.action == 'closed'
env:
REPO: ${{ inputs.repo }}
EVENT_NUMBER: ${{ inputs.event_number }}
run: |
SERVICE_NAME="deploy-preview-${REPO}-${EVENT_NUMBER}"
if gcloud run services describe $SERVICE_NAME --region=${{ env.CLOUD_RUN_REGION }} --project=grafanalabs-dev > /dev/null 2>&1; then
gcloud run services delete $SERVICE_NAME --region=${{ env.CLOUD_RUN_REGION }} --project=grafanalabs-dev --quiet
else
echo "Service $SERVICE_NAME does not exist. Skipping step."
fi
- name: Send commit status
uses: ouzi-dev/commit-status-updater@26588d166ff273fc4c0664517359948f7cdc9bf1 # v2.0.2
if: github.event.action == 'opened' || github.event.action == 'synchronize'
with:
name: deploy_preview
status: "${{ job.status }}"
url: "${{ steps.deploy.outputs.url }}${{ inputs.relative_prefix }}"
description: "Public deploy preview"

- name: Create comment with available deploy preview
if: (github.event.action == 'opened' || github.event.action == 'synchronize') && steps.fc.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
issue-number: ${{ inputs.event_number }}
body: |
:computer: Deploy preview available: ${{ steps.deploy.outputs.url }}${{ inputs.relative_prefix }}
- name: Update comment with deleted deploy preview
if: github.event.action == 'closed'
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
issue-number: ${{ inputs.event_number }}
comment-id: ${{ steps.fc.outputs.comment-id }}
edit-mode: replace
body: |
:computer: Deploy preview deleted.
- name: Update comment with available deploy preview
if: (github.event.action == 'opened' || github.event.action == 'synchronize') && steps.fc.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ inputs.event_number }}
edit-mode: replace
body: |
:computer: Deploy preview available: ${{ steps.deploy.outputs.url }}${{ inputs.relative_prefix }}

0 comments on commit b887ce8

Please sign in to comment.