Comments (8)
Hi, thanks for the report! We're slowly but surely building out APIs in wrangler, so once we have a import { pagesPublish } from 'wrangler'
(or similar) surface, we'll be able to properly address this problem.
from pages-action.
Great. That's a good solution for this github action indeed! I'd still argue that a --json
option could be helpful for the wrangler CLI in general :-)
from pages-action.
@jasikpark This might interest you. I managed to get the alias with the below setup.
After deploying I make a request to the Cloudflare API to get the alias. You just need to replace YOUR_POJECT_NAME
in the endpoint and it should work. You can then use ${{ steps.get-alias.outputs.alias }}
as you see fit:
- name: Publish
id: cloudflare
uses: cloudflare/pages-action@1
with:
... All your settings
- name: Get Deployment Alias
if: github.event_name == 'pull_request'
id: get-alias
run: |
sleep 20s
deployment_response=$(curl --request GET --url https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/YOUR_POJECT_NAME/deployments/${{ steps.cloudflare.outputs.id }} --header 'Content-Type: application/json' -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}")
alias=$(jq -r '.result.aliases[0]' <<< "$deployment_response")
echo "alias=$alias" >> "$GITHUB_OUTPUT"
- name: Echo outputs
run: |
echo ${{ steps.cloudflare.outputs.id }}
echo ${{ steps.cloudflare.outputs.url }}
echo ${{ steps.cloudflare.outputs.environment }}
echo ${{ steps.get-alias.outputs.alias }}
Edit 1: Getting some mixed results when deploying the PR for the first time. Sometimes the alias is not yet available.
Edit 2: Adding the sleep 20s
before making the request seems to work well enough.
from pages-action.
Sorry, meant to add a link to the code in question: https://github.com/cloudflare/pages-action/blob/main/src/index.ts#L68-L74
from pages-action.
Is there any progress on this? sorry to poke :p I suppose this is still blocked on wrangler having a JS api?
https://github.com/cloudflare/wrangler2/blob/main/packages/wrangler/src/pages/publish.tsx
my main interest is getting consistent alias
output so that I can generate useful links to the deploy previews
from pages-action.
Sorry to poke again, but is there any work I can do to help move this along? I have a script that creates a facimile address by just appending
`${branchName}${cfpages-preview-url}`
but this doesn't work due to DNS encoding values and truncation of the url. I suppose I could just reverse engineer what the rest of the algo is 🤷
from pages-action.
My current solution is to just manually generate the deploy url from the branch name:
/** Discovered from generated urls in the CloudFlare Dashboard */
const MAX_LENGTH_SUBDOMAIN = 28;
/**
* {@link genDeployURL} tries to take the branch for a deploy preview and generate the same subdomain that CloudFlare does.
* @param props {{ branchName: string }}
*/
export default function genDeployURL({ branchName }) {
let formattedSubdomain = branchName
.toLowerCase()
.replace(/[_|\/]/g, '-')
.slice(0, MAX_LENGTH_SUBDOMAIN);
// Do not end the subdomain with an `-`.
if (formattedSubdomain.endsWith('-')) {
formattedSubdomain = formattedSubdomain.slice(0, formattedSubdomain.length - 1);
}
return formattedSubdomain;
}
- name: Generate CF Deploy Preview URL
id: deploy-preview-url-gen
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const { default: script } = await import('${{ github.workspace }}/.github/scripts/gen-deploy-url.mjs')
return script({ branchName: '${{ steps.branch-name.outputs.current_branch }}' })
This may yet be incomplete, but it's been good enough for me for now. I use a GA to grab the true branch name and another GA to comment on the PR with the deploy details.
from pages-action.
I agree that the alias output from the publish step seems to always be the deployment URL. We are not making any improvements to this repo moving forward. The workarounds above will also work with wrangler-action.
from pages-action.
Related Issues (20)
- how can I set a service binding via this action? HOT 1
- Post-upload fails HOT 3
- Unable to publish site, API return 503 and 504 errors HOT 1
- Disable Wrangler
- Specifying `--compatibility-flags` HOT 2
- Action fails after Deployment complete! HOT 2
- GitHub Actions failing on run
- Deploying with cloudflare/pages-action but cannot locate sveltekit build directory HOT 2
- Update README GITHUB_TOKEN to DEPLOY_TOKEN HOT 1
- Authentication Error 10000 on endpoint /upload-token HOT 1
- Trunk based development and differentiating preview vs production env
- Project not found. The specified project name does not match any of your existing projects. HOT 1
- Transitioning from Node 16 to Node 20 HOT 27
- Impossible to set branch deployment options with this action? HOT 1
- Incorrect alias HOT 3
- "No deployment available" when deploying with this action HOT 1
- Failed runs-on windows-latest with node 18/20. But node 16 works fine.
- Using CF_PAGES_URL HOT 2
- Is this repository deprecated, unmaintained ? HOT 5
- How can I automatically post the preview address as a comment? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pages-action.