rxdi / firelink

Firebase. gcloud and monorepos are not combining very well until they met @rxdi/firelink
MIT License
68 stars 9 forks source link

Using firelink in GitHub actions #45

Closed yaron1m closed 2 years ago

yaron1m commented 2 years ago

Hi,

I want to deploy my firebase functions from Github Actions. Until I started using firelink I used w9jds/firebase-action, but this does not work with firelink.

How can I deploy my firebase functions from GitHub actions using firelink? Are there plans to create a dedicated action for firelink?

Alternatively, is there an option to run firelink without the actual deployment (i.e. just the file generation)? I would love an option to run firelink --onlyCopyFiles and then run the action above.

Thanks!

Stradivario commented 2 years ago

Hello there @yaron1m and thank you for the ticket!

I think what you need to do is just run firelink without any arguments until i think of better solution and test out some scenarios with this github action. Notice the job for Copy packages with Firelink it should be pretty simple but i need to test it out.

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@master
      - name: Install Dependencies
        run: npm install
      - name: Copy packages with Firelink
        run: npx firelink
      - name: Build
        run: npm run build-prod
      - name: Archive Production Artifact
        uses: actions/upload-artifact@master
        with:
          name: dist
          path: dist

Stay tuned

Regards, Kristiyan Tachev

yaron1m commented 2 years ago

Thanks @Stradivario!

This solution is almost working. It does create the .packages folder correctly but is missing one part - changing the path of the dependency library from ^1.0.0 to file:..., this the deployment still fails.

I managed to solve that by running firelink --leave-changes in the action:

      - name: Install firelink
        run: npm i -g @rxdi/firelink

      - name: Run firelink
        working-directory: ./firebase/functions
        run: npx firelink --leave-changes

      - name: Deploy to Firebase Functions
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only functions
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

But, this also fails, because it expects firebase-tools to be installed. I also notice that after running firelink the output is similar to running firebase --help which is a bit confusing.

Run firelink --leave-changes
  firelink --leave-changes
  shell: /usr/bin/bash -e ***0***
command not found: firebase
Error: Process completed with exit code 1.

My temporary solution to this was to also install firebase-tools globally

      - name: Install deployment dependencies
        run: npm i -g @rxdi/firelink firebase-tools

Here's what I suggest: Create a new flag for firelink - --onlyCopyFiles (or any other name) that will:

  1. Copy the files to .packages.
  2. Edit package.json and create the backup file.
  3. Not trigger firebase in any way.

What do you think?

Stradivario commented 2 years ago

Hello there @yaron1m !

I just created a PR with i hope that this will be the appropriate way to fix your issue.

The command that you are looking for will be:

firelink --no-runner --leave-changes

This command i think will satisfy all 3 needs written

  1. Copy the files to .packages.
  2. Edit package.json and create the backup file.
  3. Not trigger firebase in any way.

If you do want to revert changes u can use command --revert-changes

firelink --no-runner --revert-changes

If you want just to prepare the environment and do the magic of firelink this command will just not execute the defined script at the end aka firebase which is by default or other predefined inside fireConfig.runner

firelink --no-runner

Expect a version bump in about an hour!

Cheers and please tell me if this command is working for you so we can close that ticket :)

Feel free to contact me for any details regarding anything :)

Cheers, Kristiyan Tachev

yaron1m commented 2 years ago

Nice!

I will give it a try in the next few days and let you know if this is working :)

Thank you for your great work! Yaron

Stradivario commented 2 years ago

@yaron1m awesome mate i appreciate it a lot!

But, this also fails, because it expects firebase-tools to be installed. I also notice that after running firelink the output is similar to running firebase --help which is a bit confusing.

One thing i didn't answer is that firebase command is the default runner and this is why by default requires firebase-tools I think this should change in the future and remove the need for command to be executed if not specified. That way this library can be used with any tool or workflow.

I am preparing now a PR with complete refactoring of the code since i wasn't prepared for such an attention regarding this library and we need to move faster in order to be easy for usage and development. U can track the progress here for the actual refactoring.

https://github.com/rxdi/firelink/pull/47 https://github.com/rxdi/firelink/issues/48

Library will be refactored using Functional programming approach and i will provide some useful tools like UI that can be added as a Plugin to the system.

You can install the new version with npm install @rxdi/firelink@0.8.0

Regards!

yaron1m commented 2 years ago

I just tested this and it worked great:

      - name: Install deployment dependencies
        run: npm i -g @rxdi/firelink

      - name: Run firelink
        working-directory: ./firebase/functions
        run: firelink --no-runner --leave-changes

      - name: Deploy to Firebase Functions
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only functions
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

Thank you!

Stradivario commented 2 years ago

I just tested this and it worked great:

      - name: Install deployment dependencies
        run: npm i -g @rxdi/firelink

      - name: Run firelink
        working-directory: ./firebase/functions
        run: firelink --no-runner --leave-changes

      - name: Deploy to Firebase Functions
        uses: w9jds/firebase-action@master
        with:
          args: deploy --only functions
        env:
          FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

Thank you!

Oh man that looks like "pure ore" i like it how clean it is !

I am glad you create this ticket and help the library to become better ! Thanks !

Cheers!

EDIT: I am thinking even to add this example inside the readme so more people will know how to do that !

Stradivario commented 2 years ago

Feel free to open this issue again if needed!

Cheers!