Skip to content

Commit

Permalink
feat: adds workflow to deploy to testnet (#305)
Browse files Browse the repository at this point in the history
* feat: adds workflow to deploy to testnet

* fix: prettier

* fix: build script

* feature: devhub.testnet workflow

* feat: creates dev script

* feat: replaces release workflow

* feat: adds weekly promotion of develop to main
  • Loading branch information
elliotBraem authored Oct 18, 2023
1 parent 00dac74 commit e0dc11d
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 15 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/deploy-dev-testnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy Widgets to Testnet Dev
on:
push:
branches: [develop]
jobs:
deploy-widgets:
runs-on: ubuntu-latest
name: Deploy widgets to devhub-dev.testnet
env:
NEAR_SOCIAL_ACCOUNT_ID: ${{ vars.NEAR_SOCIAL_TESTNET_DEV_ACCOUNT_ID }}
NEAR_SOCIAL_ACCOUNT_PUBLIC_KEY: ${{ vars.NEAR_SOCIAL_TESTNET_DEV_ACCOUNT_PUBLIC_KEY }}
NEAR_SOCIAL_ACCOUNT_PRIVATE_KEY: ${{ secrets.NEAR_SOCIAL_TESTNET_DEV_ACCOUNT_PRIVATE_KEY }}

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

- name: Set replacements
id: set_replacements
run: |
echo "replacements=$(jq -r '[to_entries[] | .["find"] = "${" + .key + "}" | .["replace"] = .value | del(.key, .value)]' replacements.dev.json | tr -d "\n\r")" >> $GITHUB_OUTPUT
- name: Replace placeholders
uses: flcdrg/replace-multiple-action@v1
with:
files: '**/*.jsx'
find: '${{ steps.set_replacements.outputs.replacements }}'
prefix: '(^|.*)'
suffix: '($|.*)'

- name: Install bos CLI
run: |
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/FroVolod/bos-cli-rs/releases/download/v0.3.5/bos-cli-v0.3.1-installer.sh | sh
- name: Deploy widgets
run: |
which bos
echo $PATH
bos components deploy "$NEAR_SOCIAL_ACCOUNT_ID" sign-as "$NEAR_SOCIAL_ACCOUNT_ID" network-config testnet sign-with-plaintext-private-key --signer-public-key "$NEAR_SOCIAL_ACCOUNT_PUBLIC_KEY" --signer-private-key "$NEAR_SOCIAL_ACCOUNT_PRIVATE_KEY" send
40 changes: 40 additions & 0 deletions .github/workflows/deploy-prod-mainnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Deploy Widgets to Mainnet
on:
push:
branches: [main]
jobs:
deploy-widgets:
runs-on: ubuntu-latest
name: Deploy widgets to social.near (mainnet)
env:
NEAR_SOCIAL_DEPLOY_ID: ${{ vars.NEAR_SOCIAL_ACCOUNT_ID }}
NEAR_SOCIAL_ACCOUNT_ID: ${{ vars.NEAR_SOCIAL_ACCOUNT_ID }}
NEAR_SOCIAL_ACCOUNT_PUBLIC_KEY: ${{ vars.NEAR_SOCIAL_ACCOUNT_PUBLIC_KEY }}
NEAR_SOCIAL_ACCOUNT_PRIVATE_KEY: ${{ secrets.NEAR_SOCIAL_ACCOUNT_PRIVATE_KEY }}

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

- name: Set replacements
id: set_replacements
run: |
echo "replacements=$(jq -r '[to_entries[] | .["find"] = "${" + .key + "}" | .["replace"] = .value | del(.key, .value)]' replacements.mainnet.json | tr -d "\n\r")" >> $GITHUB_OUTPUT
- name: Replace placeholders
uses: flcdrg/replace-multiple-action@v1
with:
files: '**/*.jsx'
find: '${{ steps.set_replacements.outputs.replacements }}'
prefix: '(^|.*)'
suffix: '($|.*)'

- name: Install bos CLI
run: |
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/FroVolod/bos-cli-rs/releases/download/v0.3.2/bos-cli-installer.sh | sh
- name: Deploy widgets
run: |
which bos
echo $PATH
bos components deploy "$NEAR_SOCIAL_DEPLOY_ID" sign-as "$NEAR_SOCIAL_ACCOUNT_ID" network-config mainnet sign-with-plaintext-private-key --signer-public-key "$NEAR_SOCIAL_ACCOUNT_PUBLIC_KEY" --signer-private-key "$NEAR_SOCIAL_ACCOUNT_PRIVATE_KEY" send
39 changes: 39 additions & 0 deletions .github/workflows/deploy-prod-testnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Deploy Widgets to Testnet
on:
push:
branches: [main]
jobs:
deploy-widgets:
runs-on: ubuntu-latest
name: Deploy widgets to devhub.testnet
env:
NEAR_SOCIAL_ACCOUNT_ID: ${{ vars.NEAR_SOCIAL_TESTNET_ACCOUNT_ID }}
NEAR_SOCIAL_ACCOUNT_PUBLIC_KEY: ${{ vars.NEAR_SOCIAL_TESTNET_ACCOUNT_PUBLIC_KEY }}
NEAR_SOCIAL_ACCOUNT_PRIVATE_KEY: ${{ secrets.NEAR_SOCIAL_TESTNET_ACCOUNT_PRIVATE_KEY }}

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

- name: Set replacements
id: set_replacements
run: |
echo "replacements=$(jq -r '[to_entries[] | .["find"] = "${" + .key + "}" | .["replace"] = .value | del(.key, .value)]' replacements.testnet.json | tr -d "\n\r")" >> $GITHUB_OUTPUT
- name: Replace placeholders
uses: flcdrg/replace-multiple-action@v1
with:
files: '**/*.jsx'
find: '${{ steps.set_replacements.outputs.replacements }}'
prefix: '(^|.*)'
suffix: '($|.*)'

- name: Install bos CLI
run: |
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/FroVolod/bos-cli-rs/releases/download/v0.3.5/bos-cli-installer.sh | sh
- name: Deploy widgets
run: |
which bos
echo $PATH
bos components deploy "$NEAR_SOCIAL_ACCOUNT_ID" sign-as "$NEAR_SOCIAL_ACCOUNT_ID" network-config testnet sign-with-plaintext-private-key --signer-public-key "$NEAR_SOCIAL_ACCOUNT_PUBLIC_KEY" --signer-private-key "$NEAR_SOCIAL_ACCOUNT_PRIVATE_KEY" send
22 changes: 22 additions & 0 deletions .github/workflows/promote-develop-to-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: weekly-production-release

on:
schedule:
- cron: '0 0 * * THU'

permissions:
pull-requests: write

jobs:
pull-request:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: pull-request
run: |
gh pr create --base main --head develop -f -a ailisp -a frol --title "weekly promotion of develop to main"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 changes: 0 additions & 13 deletions .github/workflows/release.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
.vscode
.DS_Store

// replacements
replacements.*.json.tmp
55 changes: 54 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,63 @@ You can also explore a list of [good first issues](https://github.com/near/devgi

We use `npm` and scripts in `package.json` to automate common developer tasks, so you will need NodeJS and then install project dependencies as usual:

```
```sh
npm install
```

### Development

#### Run the dev script

To initiate the development environment, you can use the following script. This script will first check if bos-loader is installed and, if not, install it. Then, it will serve the default development environment.

```sh
npm run dev
```

#### Customizing Creator ID, Contract ID, or Network

If you need to customize the account ID, override the contract ID, or specify a different network for your development environment, you can use the following flags:

-a or --account: Specify the desired account ID.
-c or --contract: Override the default contract ID.
-n or --network: Set the network environment.

Here's how you can use these flags:

```sh
npm run dev -a your_account_id -c your_contract_id -n your_network
```

For example:

```sh
npm run dev -a bob.near -c contract.bobs.near -n mainnet
```

By using these flags, you have the flexibility to customize the development environment according to your specific needs.


#### Developing across multiple environments

When referencing a component or any parameter that depends on the network, please use the placeholders defined in replacements.*.json. There are three such files that correspond to different environments:

`replacements.dev.json` - deploys the develop branch, to testnet @ test.beta.near.org

`replacements.testnet.json` - deploys main branch, to testnet @ test.near.org

`replacements.mainnet.json` - deploys main branch to mainnet @ near.org

Placeholders should be encapsulated in the ${} expression. Here is an example of a placeholder usage:

`<Widget src={homepage ?? "${REPL_ACCOUNT}/widget/ActivityPage"} />`

Placeholders are replaced with the target values specified in replacements.json when github actions deploys the components.

Feel free to specify a new placeholder if needed. The placeholder should have a REPL prefix, for example: `REPL_PROJECT_NAME`

A new placeholder should be defined for all three environments: dev-testnet, prod-testnet and prod-mainnet.

### Deployment

#### Deploy for Local Development and Testing
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"fmt": "prettier --write '**/*.{js,jsx,ts,tsx,json}'",
"fmt:check": "prettier --check '**/*.{js,jsx,ts,tsx,json}'",
"build": "npm run fmt && node ./module/include.js",
"dev": "~/.cargo/bin/bos-loader devgovgigs.near --path src",
"dev": "sh ./scripts/dev.sh",
"test": "npx playwright test"
},
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions replacements.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"REPL_DEVHUB": "devhub-dev.testnet",
"REPL_DEVHUB_CONTRACT": "thomaspreview.testnet",
"REPL_NEAR": "discom.testnet",
"REPL_MOB": "eugenethedream",
"REPL_EFIZ": "efiz.testnet"
}
7 changes: 7 additions & 0 deletions replacements.testnet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"REPL_DEVHUB": "devhub.testnet",
"REPL_DEVHUB_CONTRACT": "thomaspreview.testnet",
"REPL_NEAR": "discom.testnet",
"REPL_MOB": "eugenethedream",
"REPL_EFIZ": "efiz.testnet"
}
61 changes: 61 additions & 0 deletions scripts/dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash

# Check if bos-loader is installed
if ! command -v bos-loader &> /dev/null; then
# Install bos-loader
echo "bos-loader is not installed. Installing..."
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/mpeterdev/bos-loader/releases/download/v0.7.1/bos-loader-v0.7.1-installer.sh | sh
fi

# Define default values
ACCOUNT_ID="devhub.testnet"
CONTRACT_ID="devhub.testnet"
NETWORK_ENV="testnet"
CREATOR_REPL="REPL_DEVHUB"
CONTRACT_REPL="REPL_DEVHUB_CONTRACT"

# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-a|--account)
ACCOUNT_ID="$2"
shift
shift
;;
-c|--contract)
CONTRACT_ID="$2"
shift
shift
;;
-n|--network)
NETWORK_ENV="$2"
shift
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done

# Convert NETWORK_ENV to lowercase
NETWORK_ENV=$(echo "$NETWORK_ENV" | tr '[:upper:]' '[:lower:]')

echo "NETWORK_ENV: $NETWORK_ENV"

# Update the value in replacements.json
REPLACEMENTS_JSON="replacements.$NETWORK_ENV.json"

if [ -f "$REPLACEMENTS_JSON" ]; then
# Replace the value in the JSON file

jq --arg ACCOUNT_ID "$ACCOUNT_ID" --arg CONTRACT_ID "$CONTRACT_ID" ".[\"$CREATOR_REPL\"] = \"$ACCOUNT_ID\" | .[\"$CONTRACT_REPL\"] = \"$CONTRACT_ID\"" "$REPLACEMENTS_JSON" > "$REPLACEMENTS_JSON.tmp"
else
echo "Error: $REPLACEMENTS_JSON file not found."
exit 1
fi

# Run bos-loader with updated replacements
bos-loader "$ACCOUNT_ID" --path src -r "$REPLACEMENTS_JSON"

0 comments on commit e0dc11d

Please sign in to comment.