Skip to content

Commit

Permalink
Added CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaljanicki committed Feb 26, 2024
1 parent 3da0fd2 commit 81e1e8d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Publish frontend

on:
push:
branches:
- develop
- master

env:
NODE_VERSION: 18.x

jobs:
set_environment:
runs-on: ubuntu-latest

steps:
- name: Set up environment based on branch
id: environment_check
run: |
SIMPLE_REF=$(echo ${GITHUB_REF#refs/heads/} | tr / -)
[ "$SIMPLE_REF" = "master" ] && ENV_NAME="prod" || ENV_NAME="$SIMPLE_REF"
echo "env_name=${ENV_NAME}" >> $GITHUB_OUTPUT
outputs:
env_name: ${{ steps.environment_check.outputs.env_name }}

build:
runs-on: ubuntu-latest
needs: [set_environment]
permissions:
id-token: write
contents: read

environment:
name: ${{ needs.set_environment.outputs.env_name }}

steps:
- uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.GH_OIDC_ROLE_ARN }}
aws-region: ${{ vars.AWS_REGION }}

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install Node requirements
run: npm i

- name: Install Python requirements
run: pip install -r requirements.txt

- name: Deploy Serverless Lambda functions
env:
PUBLISH_DOCS_USERNAME: ${{ vars.PUBLISH_DOCS_USERNAME }}
PUBLISH_DOCS_PASSWORD: ${{ vars.PUBLISH_DOCS_PASSWORD }}
run: npm run publish-${{ needs.set_environment.outputs.env_name }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*node_modules
*node_modules
.idea
dist/
1 change: 0 additions & 1 deletion dist/app.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/license.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config webpack.config.js",
"publish": "npm run build && python publish.py",
"publish-develop": "npm run build && python publish.py",
"publish-prod": "npm run build && python publish.py --stage prod"
},
"repository": {
Expand Down
15 changes: 8 additions & 7 deletions publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

fapp = flask.Flask('pub', template_folder='.')

API_BASE_URL = {"dev": "https://q6kkptbenj.execute-api.us-east-1.amazonaws.com/dev/",
API_BASE_URL = {"develop": "https://q6kkptbenj.execute-api.us-east-1.amazonaws.com/dev/",
"prod": "https://w3qym6pdvb.execute-api.us-east-1.amazonaws.com/"}

LANDING_PAGE = {"dev": 91469,
LANDING_PAGE = {"develop": 91469,
"prod": 87812}

LICENSE_PAGE = {"dev": 91471,
LICENSE_PAGE = {"develop": 91471,
"prod": 91164}

'''
Expand Down Expand Up @@ -94,7 +94,7 @@ def update_wordpress_page(pageId, content):


def main(argv):
stage = 'dev'
stage = 'develop'
try:
opts, args = getopt.getopt(argv,"h",['stage='])
except getopt.GetoptError:
Expand All @@ -108,8 +108,8 @@ def main(argv):
stage = arg
print('Stage is "%s"' % (stage))

if stage != 'dev' and stage != 'prod':
print("Stages 'prod' + 'dev' are only supported stages currently")
if stage != 'develop' and stage != 'prod':
print("Stages 'prod' + 'develop' are only supported stages currently")
sys.exit()

if 'PUBLISH_DOCS_USERNAME' in os.environ and 'PUBLISH_DOCS_PASSWORD' in os.environ:
Expand All @@ -127,9 +127,10 @@ def main(argv):
rendered_content = render_template('html/view-license.html', **tmpl_vars)
pageContent = update_wordpress_page(LICENSE_PAGE[stage], rendered_content)
else:
print("Environment varisbles for PUBLISH_DOCS_USERNAME and PUBLISH_DOCS_PASSWORD must be set")
print("Environment variables for PUBLISH_DOCS_USERNAME and PUBLISH_DOCS_PASSWORD must be set")
sys.exit()


if __name__ == "__main__":
main(sys.argv[1:])

0 comments on commit 81e1e8d

Please sign in to comment.