IDEMSInternational / open-app-builder

PLH App Frontend
GNU General Public License v3.0
6 stars 25 forks source link

[FEATURE] - Templated firebase hosting and actions #2236

Open chrismclarke opened 6 months ago

chrismclarke commented 6 months ago

Update 2024-03-26

Templating system implemented in https://github.com/IDEMSInternational/parenting-app-ui/pull/2251, android and ios config migrated, so all that remains should be firebase hosting config files (firebase.json, .firebaserc) and related github actions.

Recommend creating a yarn workflow firebase command that by default calls a child configure command (also available as yarn workflow firebase configure), which populates the variables, ideally providing default values from the firebase config where possible (e.g. default hosting id same as project id?), and throwing an error if firebase config not set. Once workflow configured github actions should be updated to call.

Alternatively could still use github actions/shell scripts to replace, but just replace variables instead of writing entire template. The minor benefit to this approach would be not having to checkout and install node_modules for a second time as the build action happens in isolation (see similar changes in #2278)


What? Some github actions use custom scripting to populate files using variables stored in github actions context. These scripts can be a little verbose and hard to adapt, and are somewhat detached from local workflows.

E.g. reusable-deploy-pr-preview action

It might be more useful to implement a templating system that can be used either as part of github actions or locally to populate files as required.

How? There's no shortage of tools around for templating, however preferably it would be good to find one that can be run both locally and as part of CI. Given that github actions can execute any javascript actions directly it may be preferable to use a javascript/node-based solution as opposed to one that is installed through docker, or at least a templating syntax that is interoperable.

It might also be worth considering creating a custom github action for handling this (or using existing). Github action providers typescript and javascript starter templates, e.g. https://github.dev/actions/typescript-action

Other details Example tools to consider:

Example of template file that could be used as generator for .firebaserc (env_substr format)

{
  "projects": {
    "default": "${FIREBASE_PROJECT_ID}"
  },
  "targets": {
    "${FIREBASE_PROJECT_ID}": {
      "hosting": {
        "${FIREBASE_HOSTING_TARGET}": [
          "${FIREBASE_PROJECT_ID}"
        ]
      }
    }
  },
  "etags": {}
}

Current code used to generate .firebaserc

run: |
          FIREBASE_RC_TARGETS=$(jq -n \
            --argjson "${{env.FIREBASE_PROJECT_ID}}" \
            '{"hosting":{"${{env.FIREBASE_HOSTING_TARGET}}":["${{env.FIREBASE_HOSTING_TARGET}}"]}}' \
            '$ARGS.named'
            )
          FIREBASE_RC=$(jq -n \
          --argjson projects '{"default":"${{env.FIREBASE_PROJECT_ID}}"}' \
          --argjson targets "$FIREBASE_RC_TARGETS" \
          '$ARGS.named'
          )
          echo $FIREBASE_RC | jq '.'
          echo $FIREBASE_RC > .firebaserc