Skip to content

Commit

Permalink
adapt the workflow for local testing
Browse files Browse the repository at this point in the history
adapt trigger type

remove duplicate id

testing

test

testing dai

clean up the repo
  • Loading branch information
Marcin Górny committed Jan 4, 2021
1 parent 6955df6 commit 43b2c91
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 13 deletions.
1 change: 1 addition & 0 deletions .actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-P ubuntu-latest=nektos/act-environments-ubuntu:18.04
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ACT=true
36 changes: 36 additions & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Testing workflows

While it requires some assumptions & is somewhat limited in scope, it's possible to run local testing on some of the workflows

## Setup
0. Setup your Google API Credentials on https://console.developers.google.com/
- Credentials -> Create Credentials -> Service Accounts

1. Follow the instructions for installing [act](https://github.com/nektos/act)

2. The act environment is configured via `.actrc` & `.env` files. For this repo, we set:
- the docker image used for testing to `nektos/act-environments-ubuntu:18.04`, corresponding to GitHub's test environment. Probably not all features are necessary, but we rely for example on the presence of `jq` in the image for JSON parsing
- `ACT=true` environment variable. This way we can distinguish which steps to run

3. Pull the above mentioned docker image:
`docker pull nektos/act-environments-ubuntu:18.04`

### Local Testing

4. Modify the `google_sheet_update.yml` to replace the `parse files` section with `local testing parse files` (since they have the same ID, they can't both be used in the yml or else GitHub will complain). They should both be there by default, it's just a matter of commenting one section out

### Fork Testing
4. Fork the Open Grants Repo

5. Set up your secrets under the fork/settings:
- GSHEET_PRIVATE_KEY
- GSHEET_CLIENT_EMAIL
- SPREADSHEET_ID

6. Branch off from master. Create a PR with only 1 file added (e.g. `cp applications/workflow_testing.md applications/workflow_testing_2.md`, add & commit it). To trigger the workflow, you need to merge the PR (into your own fork). Note: Push any changes to fork's master branch before you branch off, because the workflow to run will be the one from master.

## Usage

```
act -s GSHEET_PRIVATE_KEY="$(< .gsheet_private_key)" -s GSHEET_CLIENT_EMAIL="$(< .gsheet_client_email)" -s SPREADSHEET_ID="$(< .spreadsheet_id)" -e .pr_event.json -j update_sheet
```
35 changes: 22 additions & 13 deletions .github/workflows/google_sheet_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,39 @@ name: Google Sheet Update
on:
pull_request_target:
types: [closed]
# on: push

jobs:
fetch:
update_sheet:
runs-on: ubuntu-latest
steps:
- name: 'get all added files in the PR'
if: github.event.pull_request.merged == true
if: ${{ github.event.pull_request.merged == true && !env.ACT }}
id: 'files'
uses: mmagician/get-changed-files@v0.0.1
uses: mmagician/get-changed-files@master

- uses: actions/checkout@master
if: github.event.pull_request.merged == true
name: Checkout
- name: Checkout
uses: actions/checkout@master
if: ${{ github.event.pull_request.merged == true && !env.ACT }}
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Local Testing Checkout
uses: actions/checkout@master
if: ${{ env.ACT }}

# - name: 'local testing parse files'
# if: ${{ env.ACT }}
# id: grant_parser
# uses: mmagician/read-file-action@v1
# with:
# path: 'applications/workflow_testing.md'

- name: 'parse files'
if: github.event.pull_request.merged == true
if: ${{ github.event.pull_request.merged == true && !env.ACT }}
id: grant_parser
uses: mmagician/read-file-action@v0.1.2
uses: mmagician/read-file-action@v1
with:
path: "${{ github.workspace }}/${{ steps.files.outputs.added }}"
# local testing only
# path: 'applications/workflow_testing_12.md'

- name: Get current date
if: github.event.pull_request.merged == true
Expand All @@ -39,7 +47,7 @@ jobs:
uses: mmagician/[email protected]
with:
spreadsheetId: ${{ secrets.SPREADSHEET_ID }}
startRow: 196
startRow: 220
worksheetTitle: "Legal"
env:
GSHEET_CLIENT_EMAIL: ${{ secrets.GSHEET_CLIENT_EMAIL }}
Expand Down Expand Up @@ -72,7 +80,8 @@ jobs:
"https://github.com/w3f/Open-Grants-Program/pull/${{ github.event.pull_request.number }}",
"https://github.com/w3f/Open-Grants-Program/pull/${{ github.event.pull_request.number }}",
"USD", "0", "0", "0",
"${{ steps.grant_parser.outputs.total_cost }}",
"${{ steps.grant_parser.outputs.total_cost_btc }}",
"${{ steps.grant_parser.outputs.total_cost_dai }}",
"",
"",
"Executed",
Expand Down
14 changes: 14 additions & 0 deletions .pr_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pull_request": {
"head": {
"ref": "10e629ef2f090f55a52b693961de8f5e1206d900"
},
"base": {
"ref": "10e629ef2f090f55a52b693961de8f5e1206d900"
},
"state": "closed",
"merged": true,
"number": 12,
"body": "# Grant Application Checklist\n- [X] The [application-template.md](https://github.com/w3f/Open-Grants-Program/blob/master/applications/application-template.md) has been copied, renamed ( \"project_name.md\") and updated."
}
}
18 changes: 18 additions & 0 deletions applications/workflow_testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Open Grant Proposal

* **Project Name:** DuoSwap Module
* **Team Name:** Duo
* **Payment Address:** 123mp123

### Contact
* **Contact Name:** John Brown
* **Contact Email:** [email protected]

### Legal Structure
* **Registered Address:** High Street 1, London LK1 234, UK
* **Registered Legal Entity:** Duo Ltd.

### Overview
* **Total Estimated Duration:** 2 months
* **Total Costs:** 0.80 btc

0 comments on commit 43b2c91

Please sign in to comment.