Azure: use shared env setter, fix comment workflow (#25044)
* update azure deployments to use shared env getter, fix content changes table
This commit is contained in:
@@ -1,23 +1,20 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import createStagingAppName from '../../script/deployment/create-staging-app-name.js'
|
||||
import * as github from '@actions/github'
|
||||
import { setOutput } from '@actions/core'
|
||||
|
||||
const { GITHUB_TOKEN, APP_URL } = process.env
|
||||
const context = github.context
|
||||
|
||||
const githubToken = process.env.GITHUB_TOKEN
|
||||
if (!githubToken) {
|
||||
if (!GITHUB_TOKEN) {
|
||||
throw new Error(`GITHUB_TOKEN environment variable not set`)
|
||||
}
|
||||
|
||||
const stagingPrefix = createStagingAppName({
|
||||
repo: context.payload.repository.name,
|
||||
pullNumber: context.payload.number,
|
||||
branch: context.payload.pull_request.head.ref,
|
||||
})
|
||||
if (!APP_URL) {
|
||||
throw new Error(`APP_URL environment variable not set`)
|
||||
}
|
||||
|
||||
const octokit = github.getOctokit(githubToken)
|
||||
const octokit = github.getOctokit(GITHUB_TOKEN)
|
||||
|
||||
const response = await octokit.rest.repos.compareCommits({
|
||||
owner: context.repo.owner,
|
||||
@@ -29,7 +26,7 @@ const response = await octokit.rest.repos.compareCommits({
|
||||
const { files } = response.data
|
||||
|
||||
let markdownTable =
|
||||
'| **Source** | **Staging** | **Production** | **What Changed** |\n|:----------- |:----------- |:----------- |:----------- |\n'
|
||||
'| **Source** | **Preview** | **Production** | **What Changed** |\n|:----------- |:----------- |:----------- |:----------- |\n'
|
||||
|
||||
const pathPrefix = 'content/'
|
||||
const articleFiles = files.filter(
|
||||
@@ -39,14 +36,14 @@ for (const file of articleFiles) {
|
||||
const sourceUrl = file.blob_url
|
||||
const fileName = file.filename.slice(pathPrefix.length)
|
||||
const fileUrl = fileName.slice(0, fileName.lastIndexOf('.'))
|
||||
const stagingLink = `https://${stagingPrefix}.herokuapp.com/${fileUrl}`
|
||||
const previewLink = `https://${APP_URL}/${fileUrl}`
|
||||
const productionLink = `https://docs.github.com/${fileUrl}`
|
||||
let markdownLine = ''
|
||||
|
||||
if (file.status === 'modified') {
|
||||
markdownLine = `| [content/${fileName}](${sourceUrl}) | [Modified](${stagingLink}) | [Original](${productionLink}) | |\n`
|
||||
markdownLine = `| [content/${fileName}](${sourceUrl}) | [Modified](${previewLink}) | [Original](${productionLink}) | |\n`
|
||||
} else if (file.status === 'added') {
|
||||
markdownLine = `| New file: [content/${fileName}](${sourceUrl}) | [Modified](${stagingLink}) | | |\n`
|
||||
markdownLine = `| New file: [content/${fileName}](${sourceUrl}) | [Modified](${previewLink}) | | |\n`
|
||||
}
|
||||
markdownTable += markdownLine
|
||||
}
|
||||
|
||||
41
.github/actions-scripts/get-preview-app-info.sh
vendored
Executable file
41
.github/actions-scripts/get-preview-app-info.sh
vendored
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# [start-readme]
|
||||
#
|
||||
# This script sets environment variables with info about the preview app for a given PR
|
||||
#
|
||||
# [end-readme]
|
||||
|
||||
# ENV VARS NEEDED TO RUN
|
||||
[[ -z $GITHUB_REPOSITORY ]] && { echo "Missing GITHUB_REPOSITORY. Exiting."; exit 1; }
|
||||
[[ -z $PR_NUMBER ]] && { echo "Missing PR_NUMBER. Exiting."; exit 1; }
|
||||
[[ -z $GITHUB_ENV ]] && { echo "Missing GITHUB_ENV. Exiting."; exit 1; }
|
||||
|
||||
# Number of resource groups that we use to split preview envs across
|
||||
PREVIEW_ENV_RESOURCE_GROUPS=4
|
||||
|
||||
REPO_NAME="${GITHUB_REPOSITORY#*\/}"
|
||||
echo "REPO_NAME=${REPO_NAME}" >> $GITHUB_ENV
|
||||
|
||||
DEPLOYMENT_NAME="${REPO_NAME}-pr-${PR_NUMBER}"
|
||||
echo "DEPLOYMENT_NAME=${DEPLOYMENT_NAME}" >> $GITHUB_ENV
|
||||
|
||||
RESOURCE_GROUP="preview-env-${REPO_NAME}-$((${PR_NUMBER} % ${PREVIEW_ENV_RESOURCE_GROUPS}))"
|
||||
echo "RESOURCE_GROUP=${RESOURCE_GROUP}" >> $GITHUB_ENV
|
||||
|
||||
APP_NAME_SHORT="${REPO_NAME}-preview-${PR_NUMBER}"
|
||||
echo "APP_NAME_SHORT=${APP_NAME_SHORT}" >> $GITHUB_ENV
|
||||
|
||||
IMAGE_REPO="${GITHUB_REPOSITORY}/pr-${PR_NUMBER}"
|
||||
echo "IMAGE_REPO=${IMAGE_REPO}" >> $GITHUB_ENV
|
||||
|
||||
# Since this incurs a network request and can be slow, we make it optional
|
||||
if [ $FULL_APP_INFO ]; then
|
||||
APP_INFO=$(az webapp list -g ${RESOURCE_GROUP} --query "[?tags.DocsAppName == '${APP_NAME_SHORT}'].{defaultHostName:defaultHostName, name:name} | [0]")
|
||||
|
||||
APP_URL=$(echo $APP_INFO | jq '.defaultHostName' | tr -d '"')
|
||||
echo "APP_URL=${APP_URL}" >> $GITHUB_ENV
|
||||
|
||||
APP_NAME_FULL=$(echo $APP_INFO | jq '.name' | tr -d '"')
|
||||
echo "APP_NAME_FULL=${APP_NAME_FULL}" >> $GITHUB_ENV
|
||||
fi
|
||||
Reference in New Issue
Block a user