Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

action to update settings for rapidpro workspace #7274

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fdf9be5
action to update settings for rapidpro workspace
kitsao Aug 28, 2021
397c10d
removed default group
kitsao Aug 28, 2021
8ef829f
updated action, readme
kitsao Aug 30, 2021
e81ed65
pr feedback
kitsao Sep 21, 2021
3c75c7f
javascript action
kitsao Sep 29, 2021
0f4a0bf
updated readme
kitsao Sep 29, 2021
486b2e8
regex update
kitsao Sep 29, 2021
1e6f056
Merge branch 'medic:master' into master
kitsao Sep 29, 2021
5c193f8
minor update
kitsao Oct 1, 2021
7e68f55
Merge branch 'master' of https://github.com/kitsao/cht-core
kitsao Oct 1, 2021
b27ea74
Merge branch 'medic:master' into master
kitsao Oct 12, 2021
f7e4f6a
renamed action, updated readme
kitsao Oct 14, 2021
3f7c945
Merge branch 'master' of https://github.com/kitsao/cht-core
kitsao Oct 14, 2021
9697dbf
Merge branch 'medic:master' into master
kitsao Feb 21, 2022
0bd40ad
feedback
kitsao Feb 21, 2022
3cd759a
moved action to gh-action for linting
kitsao Feb 21, 2022
dfeb36b
Merge branch 'master' of https://github.com/kitsao/cht-core
kitsao Mar 7, 2022
818c814
updates + initial test
kitsao Mar 9, 2022
69f1fae
refactoring
kitsao Mar 10, 2022
2661044
Merge branch 'master' of https://github.com/kitsao/cht-core
kitsao Mar 10, 2022
27df4ff
more refactoring
kitsao Mar 11, 2022
852dbb4
tests
kitsao Mar 21, 2022
e310c06
refactor, tests
kitsao Mar 23, 2022
369b7d4
log
kitsao Mar 23, 2022
4b42098
licences
kitsao Mar 23, 2022
61fd922
remove console.log
kitsao Mar 23, 2022
5bf27b4
updates
kitsao Mar 24, 2022
63c58bb
rid off path
kitsao Mar 24, 2022
ab11e65
minor changes
kitsao Mar 24, 2022
188e5e1
minor changes
kitsao Mar 24, 2022
015b9f4
path changes
kitsao Mar 24, 2022
e0ec7c8
module not found
kitsao Mar 24, 2022
aaaf5cd
use fs to read
kitsao Mar 24, 2022
166f8bb
cleanup
kitsao Mar 24, 2022
0a7d1b7
secrets not defined
kitsao Mar 24, 2022
87731d1
undefined variable
kitsao Mar 24, 2022
d7db057
try
kitsao Mar 24, 2022
a6b3bbc
500 statucode
kitsao Mar 24, 2022
0c878c7
refactor
kitsao Mar 24, 2022
300a579
more refactoring
kitsao Mar 24, 2022
20fcdd1
pause axios
kitsao Mar 24, 2022
8104ca9
console log
kitsao Mar 24, 2022
849215e
axios fix
kitsao Mar 24, 2022
30946fb
more refactoring
kitsao Mar 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ module.exports = function(grunt) {
'config/**/*.js',
'scripts/**/*.js',
'webapp/src/ts/**/*.component.html',
'gh-actions/**/*.js',
];
const ignore = [
'webapp/src/ts/providers/xpath-element-path.provider.ts',
Expand Down
82 changes: 82 additions & 0 deletions gh-actions/dynamic-rapidpro-workspace-settings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# dynamic-rapidpro-workspace Shared GitHub Action
The `dynamic-rapidpro-workspace-settings` is a parameterised reusable GitHub action that updates app-settings prior to compiling and uploading to a running CHT app.

### Background
This action is relevant for CHT apps that have either [outbound](https://docs.communityhealthtoolkit.org/apps/reference/app-settings/outbound/) integrations with RapidPro or logic that requires RapidPro workspace data GUIDs.
Normally, you would want a staging deployment to use the staging workspace and a production deployment to use the corresponding production workspace. This action automates the process of updating `app_settings.json` to use relevant UUIDs.

### How it works
1. It adds the configured `value_key` to CouchDB’s config storage to securely store the [credentials](https://docs.communityhealthtoolkit.org/apps/reference/app-settings/outbound/#credentials).
2. This action automatically updates the following details in outbound modules:
- `base_url` and `value_key`
- contact group UUID, if using the [groups endpoint](https://rapidpro.app.medicmobile.org/api/v2/groups). Note that the action was tested with one group.
- flow UUID, if using the [flow starts endpoint](https://rapidpro.app.medicmobile.org/api/v2/flow_starts). Note that the action was tested with one flow in two modules.
3. It replaces contents of a file, `flows.js`, in the project repository with flow UUIDs obtained from RapidPro workspace through the API. To extract the UUIDs, you can simply use the API explorer, under `/api/v2/flows.json`. A sample `flows.js` would be as follows:

```
module.exports = {
sample_flow_1_uuid: '3f6a48d3-703a-493b-bb10-f4a38a442cda',
sample_flow_2_uuid: '064107cf-9bc5-4042-a657-825fdb5a92a4',
...
};
```

> **This action can be executed jointly with other Github actions like [deploy-with-medic-conf](https://github.com/medic/cht-core/tree/master/.github/actions/deploy-with-medic-conf). However, it must be executed before other actions to update dependencies prior to compiling app settings.**

## CHT App Requirements
* cht-conf@3.3 or above

## Example GitHub Action Step

```
name: Example GitHub Workflow yml

on: ['workflow_dispatch']

jobs:
workflow_dispatch:
runs-on: ubuntu-18.04

steps:
- name: Update rapidpro workspace in app-settings
uses: 'medic/gh-actions/dynamic-rapidpro-workspace-settings@main'
with:
directory: 'my_app_folder'
hostname: myapp.staging.company.org
couch_node_name: myapp.couchdb.node.name
couch_username: ${{ secrets.CHT_STAGING_USERNAME }}
couch_password: ${{ secrets.CHT_STAGING_PASSWORD }}
rp_hostname: my.rapidpro.workspace.url
rp_api_token: ${{ secrets.RAPIDPRO_STAGING_TOKEN }}
value_key: medic.credentials.key
rp_contact_group: ${{ secrets.RAPIDPRO_STAGING_GROUP }}
rp_flows: ${{ secrets.RAPIDPRO_STAGING_FLOWS }}
write_patient_state_flow: ${{ secrets.RAPIDPRO_STAGING_WRITE_PATIENT_STATE_FLOW }}
app_settings_file: app_settings.json
flows_file: flows.js
```

### Example Action Input Variables From RapidPro Workspace

#### token
```
Token cb9affcf72f787d6f0413a3394f32e8cfff0f8ec
```

#### group
```
79abde8c-5f65-4e04-9ee1-4cecdc8852e1
```

#### flows
```
{
sample_flow_1_uuid: '3f6a48d3-703a-493b-bb10-f4a38a442cda',
sample_flow_2_uuid: '064107cf-9bc5-4042-a657-825fdb5a92a4',
...
}
```
#### write_patient_state_flow
```
c80848e1-72f3-4e86-8e9e-ce002bee4906
```
59 changes: 59 additions & 0 deletions gh-actions/dynamic-rapidpro-workspace-settings/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: 'Update rapidpro workspace settings'
inputs:
directory:
description: The path to the directory containing the configuration to be updated.
required: true
default: '.'

hostname:
description: The hostname of the instance to receive the configuration.
required: true

couch_node_name:
description: The name of your CouchDB's node.
required: true

couch_username:
description: The username of an administrator account on the instance at "inputs.hostname". This user will make the deployment.
required: true

couch_password:
description: The password for user with name "inputs.couch_username"
required: true

rp_hostname:
description: The base URL for your Rapidpro workspace.
required: true

rp_api_token:
description: The authorization token for your workspace (the real password configured in CouchDB's admin config).
required: true

value_key:
description: The password key configured in CouchDB's admin config.
required: true

rp_contact_group:
description: The UUID of the contact group to update in app-settings (optional).
required: true

rp_flows:
description: The list of flows for your workspace.
required: true

write_patient_state_flow:
description: The UUID of the flow to write patient state.
required: true

outputs:
app-settings:
description: Updated app-settings.json
value: ${{ steps.update-app-settings.outputs }}

rp_flows:
description: A flows.js file to be used in compile-app-settings
value: ${{ steps.generate-flows-js.outputs }}

runs:
using: 'node12'
main: 'dist/index.js'
Loading