11import * as core from "@actions/core" ;
22import * as github from "@actions/github" ;
33
4- import { readFile } from "node:fs/promises" ;
5-
64import {
75 CONTENT_BASE_PATH ,
86 DOCS_BASE_URL ,
97 GITHUB_ACTIONS_BOT_ID ,
108 PREVIEW_URL_REGEX ,
11- WRANGLER_LOGS_PATH ,
129} from "./constants" ;
1310
14- import { filenameToPath } from "./util" ;
11+ import { filenameToPath , slug } from "./util" ;
1512
1613async function run ( ) : Promise < void > {
1714 try {
18- if ( ! process . env . GITHUB_TOKEN ) {
19- core . setFailed ( `Could not find GITHUB_TOKEN in env` ) ;
15+ if ( ! process . env . GITHUB_TOKEN || ! process . env . GITHUB_REF_NAME ) {
16+ core . setFailed ( `Could not find GITHUB_TOKEN or GITHUB_REF_NAME in env` ) ;
2017 process . exit ( ) ;
2118 }
2219
@@ -53,22 +50,12 @@ async function run(): Promise<void> {
5350 PREVIEW_URL_REGEX . test ( comment . body ?? "" ) ,
5451 ) ;
5552
56- const previewUrl : string = (
57- await readFile ( WRANGLER_LOGS_PATH , { encoding : "utf-8" } )
58- )
59- . split ( "\n" )
60- . filter ( Boolean )
61- . map ( ( json ) => JSON . parse ( json ) )
62- . filter ( ( json ) => json . type === "version-upload" )
63- . map ( ( json ) => json . preview_url )
64- . at ( 0 ) ;
65-
66- if ( ! previewUrl ) {
67- core . setFailed ( `Found no version-upload at ${ WRANGLER_LOGS_PATH } ` ) ;
68- process . exit ( ) ;
69- }
53+ const previewUrl = {
54+ branch : `https://${ slug ( process . env . GITHUB_REF_NAME ) } .preview.developers.cloudflare.com` ,
55+ commit : `https://${ ctx . sha . slice ( 0 , 8 ) } .preview.developers.cloudflare.com` ,
56+ } ;
7057
71- core . debug ( previewUrl ) ;
58+ core . debug ( JSON . stringify ( previewUrl ) ) ;
7259
7360 const changedFiles = files
7461 . filter (
@@ -81,14 +68,14 @@ async function run(): Promise<void> {
8168 . slice ( 0 , 15 ) // Limit to 15 entries
8269 . map ( ( { filename } ) => {
8370 const original = `${ DOCS_BASE_URL } /${ filenameToPath ( filename ) } ` ;
84- const preview = `${ previewUrl } /${ filenameToPath ( filename ) } ` ;
71+ const preview = `${ previewUrl . branch } /${ filenameToPath ( filename ) } ` ;
8572
8673 core . debug ( [ filename , original , preview ] . toString ( ) ) ;
8774
8875 return { original, preview } ;
8976 } ) ;
9077
91- let comment = `**Preview URL:** ${ previewUrl } ` ;
78+ let comment = `**Preview URL:** ${ previewUrl . branch } ` ;
9279 if ( changedFiles . length !== 0 ) {
9380 comment = comment . concat (
9481 `**Files with changes (up to 15)**\n\n| Original Link | Updated Link |\n| --- | --- |\n${ changedFiles
0 commit comments