fresh icon indicating copy to clipboard operation
fresh copied to clipboard

Deploying with a Github Action to Deno Deploy is not working with Fresh 1.1.0

Open digitaldesigndj opened this issue 2 years ago • 6 comments

When my project is deployed with my Github Action, I get error like this about h Screenshot 2022-09-08 at 12 59 47 PM

Here's a deployment gone wrong fresh-strapi-q1s1v7x99dt0.deno.dev

But if I cut the action out and deploy directly, it all works fine. "Automatic" mode:

https://fresh-strapi-c8qdcmwm5rt0.deno.dev/

digitaldesigndj avatar Sep 08 '22 20:09 digitaldesigndj

GitHub Action deployment mode does not support reading deno.json yet, which is necessary for automatic JSX, because of the compilerOptions in the config file.

lucacasonato avatar Sep 08 '22 20:09 lucacasonato

@lucacasonato Is this something you and the team are looking into fixing? Another benefit would be that an import map file should be picked up correctly if specified in deno.json, right?

mariusschulz avatar Sep 08 '22 21:09 mariusschulz

Import map support already exisits

        uses: denoland/deployctl@v1
        with:
          project: test-andbounds # the name of the project on Deno Deploy
          entrypoint: main.ts # the entrypoint to deploy
          import-map: import_map.json

digitaldesigndj avatar Sep 08 '22 22:09 digitaldesigndj

If you specify the import-map key in the Action configuration, that is being respected. If you only configure the import map via deno.json though, it won't be picked up.

Similarly, a custom JSX factory already works today if you explicitly specify the @jsx React.createElement pragma in all of your component modules.

However, I think there's a case to be made that deno.json should be picked up automatically and "just work", which is what this issue should be about.

mariusschulz avatar Sep 08 '22 22:09 mariusschulz

TIL, so...

/** @jsxImportSource preact */

Magic. Thank you! And I very much agree that deno.json is the way. It should "just work" 🍋

digitaldesigndj avatar Sep 08 '22 22:09 digitaldesigndj

Really surprising that deployctl does not pick deno.json. I hope this will get fixed soon.

gmosx avatar Sep 11 '22 10:09 gmosx

```js
/** @jsxImportSource preact */

Where do I need to put this ? main.ts ?

xinha-sh avatar Sep 14 '22 05:09 xinha-sh

@xinha-sh I think you need in every file that uses the jsx renderer, so everything with .jsx or .tsx on the end? (should be your files containing JSX tags)

I think this is because the JSX is transformed to JS on a file by file basis, before Deno even really kicks off.

digitaldesigndj avatar Sep 14 '22 14:09 digitaldesigndj

To avoid having to add pragmas to all my files again, a workaround I'm using right now is to add the pragma to every relevant file dynamically with the GitHub Action, using https://github.com/impresscms-dev/prefix-or-suffix-text-files-action. Sadly it only supports specifying a single folder, with no way to do globs AFAIK, but at least it traverses the given folder recursively AND it doesn't commit anything to your repo. You can't just put ./ into path though, because then it would try to change something in the .git folder and probably binary files and all that, so you really just have to specify only folders which only contain .(j|t)sx or .(j|t)s files for this to work, luckily that was pretty straight-forward in my case, adding the job four times for these four folders I'm currently using:

name: Deploy

on: push

jobs:
  deploy:
    runs-on: ubuntu-latest

    permissions:
      id-token: write
      contents: read

    steps:
      - name: Clone repository
        uses: actions/checkout@v3

      - name: Add pragma to components
        uses: impresscms-dev/[email protected]
        with:
          path: ./components
          text: |
            /** @jsxImportSource preact */

      - name: Add pragma to islands
        uses: impresscms-dev/[email protected]
        with:
          path: ./islands
          text: |
            /** @jsxImportSource preact */

      - name: Add pragma to routes
        uses: impresscms-dev/[email protected]
        with:
          path: ./routes
          text: |
            /** @jsxImportSource preact */

      - name: Add pragma to sections
        uses: impresscms-dev/[email protected]
        with:
          path: ./sections
          text: |
            /** @jsxImportSource preact */

      - name: Deploy to Deno Deploy
        uses: denoland/deployctl@v1
        with:
          project: my-project
          entrypoint: main.js
          import-map: modules.json

Edit: In my case, this was the only way to deploy without any pragmas. Automatic deploying somehow just wouldn't work for me, showing error 502 on Deno Deploy saying "DEPLOY FAILED" but no error whatsoever in the server logs...

nnmrts avatar Sep 18 '22 19:09 nnmrts

I my case I changed my project name in deno deploy from x to y and haven't updated the project name in my .yml file

     - name: Upload to Deno Deploy
        uses: denoland/deployctl@v1
        with:
          project: "lamento-akilesh" # Update your project name here
          entrypoint: "server/entry.mjs" 
          root: "dist" 

akilesh-io avatar Jul 12 '23 11:07 akilesh-io

This is resolved in the deploy GH action. We now have a page in our documentation describing how to do that too https://fresh.deno.dev/docs/concepts/ahead-of-time-builds

marvinhagemeister avatar Sep 14 '23 11:09 marvinhagemeister