Skip to content

Commit

Permalink
Add version mismatch detection, refactor GH workflows, draft release.…
Browse files Browse the repository at this point in the history
…yml, increase prettier scope (#250)

* Refactor GH workflows

* Add version mismatch checker and UpdateClient Dialog

* Fix finalize release workflow

* Increase prettier scope

* Increase prettier coverage, add some static to prettierignore

* Add CodeQL on PR
  • Loading branch information
Reckless-Satoshi committed Sep 21, 2022
1 parent e4ddeea commit 893d6c2
Show file tree
Hide file tree
Showing 43 changed files with 6,225 additions and 5,966 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
pull_request:
branches: [ "main" ]
paths: ["frontend", "nodeapp"]
workflow_call:
inputs:
semver:
required: true
type: string

concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
Expand Down Expand Up @@ -71,6 +76,7 @@ jobs:
push: true
tags: |
recksato/robosats-client:${{ steps.commit.outputs.short }}
recksato/robosats-client:${{ inputs.semver }}
recksato/robosats-client:latest
labels: ${{ steps.meta.outputs.labels }}

75 changes: 75 additions & 0 deletions .github/workflows/codeql-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Analysis Client"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
paths:
- 'frontend'
- 'mobile'
schedule:
- cron: '39 10 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

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

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
name: "CodeQL Analysis Coordinator"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
# branches: [ "main" ]
branches: [ "main" ]
paths:
- 'api'
schedule:
- cron: '39 10 * * 2'

Expand All @@ -32,7 +34,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'python' ]
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Backend Image CI
name: Coodinator Image CI

on:
workflow_dispatch:
Expand All @@ -8,6 +8,11 @@ on:
pull_request:
branches: [ "main" ]
paths: ["api", "chat", "control", "robosats", "frontend"]
workflow_call:
inputs:
semver:
required: true
type: string

concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/django-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Django Tests

on:
workflow_dispatch:
workflow_call:
push:
branches: [ "main" ]
paths: ["api", "chat", "control", "robosats"]
Expand Down Expand Up @@ -55,4 +56,4 @@ jobs:
mv .env-sample .env
- name: 'Tests'
run: |
python manage.py test
python manage.py test
1 change: 1 addition & 0 deletions .github/workflows/frontend-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Frontend Test & Build

on:
workflow_dispatch:
workflow_call:
push:
branches: [ "main" ]
paths: [ "frontend" ]
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
with:
prettier: true
prettier_dir: frontend
# Many linting errors

## Disabled due to error
# eslint: true
# eslint_dir: frontend
77 changes: 77 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

name: Release

on:
push:
tags:
- "v*.*.*"

jobs:
check-versions:
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v3
- uses: olegtarasov/get-tag@v2.1
id: tagName
- name: 'Validate versions match (tag, backend, frontend, Android)'
id: validate
run: |
sudo apt-get install jq
clientV=$(jq -r .version frontend/package.json)
coordinatorV=$(jq -r .major version.json).$(jq -r .minor version.json).$(jq -r .patch version.json)
tagV=$(git describe --tags --abbrev=0 | sed 's/v//')
printf "Client version: ${clientV}\nCoordinator version: ${coordinatorV}\nGit tag version: ${tagV}"
if [ "$coordinatorV" = "$clientV" ] && [ "$coordinatorV" = "$tagV" ] ; then
echo "Versions match"
else
echo "Versions do not match!"; exit $ERRCODE;
fi
django-test:
uses: reckless-satoshi/robosats/.github/workflows/django-test.yml@main
needs: check-versions

frontend-build:
uses: reckless-satoshi/robosats/.github/workflows/frontend-build.yml@main
needs: check-versions

coordinator-image:
uses: reckless-satoshi/robosats/.github/workflows/coordinator-image.yml@main
needs: [django-test, frontend-build]
with:
semver: ${{ needs.check-version.tagName.outputs.tag }}

client-image:
uses: reckless-satoshi/robosats/.github/workflows/client-image.yml@main
needs: frontend-build
with:
semver: ${{ needs.check-version.tagName.outputs.tag }}

android-build:
uses: reckless-satoshi/robosats/.github/workflows/coordinator-image.yml@main
needs: frontend-build
with:
semver: ${{ needs.check-version.tagName.outputs.tag }}

changelog:
runs-on: ubuntu-20.04
steps:
- name: "Generate release changelog"
uses: heinrichreimer/github-changelog-generator-action@v2.3
with:
token: ${{ secrets.GITHUB_TOKEN }}

release:
needs: [coordinator-image, client-image, android-build, changelog]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Release
uses: softprops/action-gh-release@v1
with:
body: ${{ needs.changelog.outputs.changelog }}
12 changes: 11 additions & 1 deletion api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get_lnd_version():

robosats_commit_cache = {}
@ring.dict(robosats_commit_cache, expire=3600)
def get_commit_robosats():
def get_robosats_commit():

commit = os.popen('git log -n 1 --pretty=format:"%H"')
commit_hash = commit.read()
Expand All @@ -146,6 +146,16 @@ def get_commit_robosats():

return commit_hash

robosats_version_cache = {}
@ring.dict(robosats_commit_cache, expire=99999)
def get_robosats_version():

with open("version.json") as f:
version_dict = json.load(f)

print(version_dict)
return version_dict

premium_percentile = {}
@ring.dict(premium_percentile, expire=300)
def compute_premium_percentile(order):
Expand Down
5 changes: 3 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from api.logics import Logics
from api.messages import Telegram
from secrets import token_urlsafe
from api.utils import get_lnd_version, get_commit_robosats, compute_premium_percentile, compute_avg_premium
from api.utils import get_lnd_version, get_robosats_commit, get_robosats_version, compute_premium_percentile, compute_avg_premium

from .nick_generator.nick_generator import NickGenerator
from robohash import Robohash
Expand Down Expand Up @@ -837,7 +837,8 @@ def get(self, request):
context["last_day_volume"] = round(total_volume, 8)
context["lifetime_volume"] = round(lifetime_volume, 8)
context["lnd_version"] = get_lnd_version()
context["robosats_running_commit_hash"] = get_commit_robosats()
context["robosats_running_commit_hash"] = get_robosats_commit()
context["version"] = get_robosats_version()
context["alternative_site"] = config("ALTERNATIVE_SITE")
context["alternative_name"] = config("ALTERNATIVE_NAME")
context["node_alias"] = config("NODE_ALIAS")
Expand Down
9 changes: 2 additions & 7 deletions frontend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"react",
"react-hooks",
"@typescript-eslint",
"prettier"
],
"plugins": ["react", "react-hooks", "@typescript-eslint", "prettier"],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
Expand All @@ -39,4 +34,4 @@
"version": "detect"
}
}
}
}
4 changes: 4 additions & 0 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
src/components/payment-methods/code/code.js
static/rest_framework/**
static/admin/**
static/frontend/**
static/import_export/**
6 changes: 1 addition & 5 deletions frontend/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
],
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
"plugins": [
[
"@babel/plugin-transform-runtime",
Expand Down
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "frontend",
"version": "1.0.0",
"version": "0.2.0",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -9,7 +9,7 @@
"build": "webpack --mode production",
"lint": "eslint src/**/*.{js,ts,tsx}",
"lint:fix": "eslint --fix 'src/**/*.{js,ts,tsx}'",
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
"format": "prettier --write '**/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
},
"keywords": [],
"author": "",
Expand Down
Loading

0 comments on commit 893d6c2

Please sign in to comment.