From 7a07e484b567457778c65a37edf7eac05e96fc1c Mon Sep 17 00:00:00 2001 From: vggonzal <9Tcostoamm> Date: Thu, 17 Aug 2023 14:59:59 -0700 Subject: [PATCH] clean up --- .github/workflows/build.yml | 114 ++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d213860..25979de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,7 @@ on: env: POETRY_VERSION: "1.3.1" PYTHON_VERSION: "3.10" + PROJECT_ NAME: podaac/hydrocron REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} @@ -39,10 +40,13 @@ jobs: - uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} - - name: Install Poetry - uses: abatilo/actions-poetry@v2 - with: - poetry-version: ${{ env.POETRY_VERSION }} + + + - name: Install bumpver & poetry + run: pip3 install bumpver poetry poetry-plugin-bundle + - name: Install dependencies + run: poetry install + - name: Get version id: get-version run: | @@ -91,34 +95,21 @@ jobs: echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV echo "venue=ops" >> $GITHUB_ENV - name: Install hydrocron - run: poetry install + #if: ${{ startsWith(github.ref, 'test') }} + run: | + poetry update + poetry install - name: Lint + if: ${{ startsWith(github.ref, 'test') }} run: | poetry run pylint hydrocronapi poetry run flake8 hydrocronapi - - - ## Set environment variables - - name: Configure Initial YAML file and environment variables + - name: Install external libraries + #if: ${{ startsWith(github.ref, 'test') }} run: | - echo "THE_VERSION=${{ env.software_version }}" >> $GITHUB_ENV; - echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV; - GITHUB_REF_READABLE="${GITHUB_REF//\//-}" - echo "GITHUB_REF_READABLE=${GITHUB_REF_READABLE}" >> $GITHUB_ENV - echo "THE_ENV=sit" >> $GITHUB_ENV - echo "TARGET_ENV_UPPERCASE=SIT" >> $GITHUB_ENV - - # Setup Node to install and test - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 14 - - - name: NPM install - run: npm install - - name: Run Snyk as a blocking step + if: ${{ startsWith(github.ref, 'test') }} uses: snyk/actions/python-3.9@master env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} @@ -130,6 +121,7 @@ jobs: --severity-threshold=high --fail-on=all - name: Run Snyk on Python + if: ${{ startsWith(github.ref, 'test') }} uses: snyk/actions/python-3.9@master env: SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} @@ -150,10 +142,10 @@ jobs: git commit -am "/version ${{ env.software_version }}" git push - name: Push Tag - if: | - github.ref == 'refs/heads/develop' || - github.ref == 'refs/heads/main' || - startsWith(github.ref, 'refs/heads/release') + #if: | + # github.ref == 'refs/heads/develop' || + # github.ref == 'refs/heads/main' || + # startsWith(github.ref, 'refs/heads/release') run: | git config user.name "${GITHUB_ACTOR}" git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" @@ -162,27 +154,50 @@ jobs: - name: Build Python Artifact run: | poetry build - poetry self add poetry-plugin-bundle - #- name: Setup local DynamoDB - # run: docker run -d -p 8000:8000 amazon/dynamodb-local + - name: Setup local DynamoDB + if: ${{ startsWith(github.ref, 'test') }} + run: docker run -d -p 8000:8000 amazon/dynamodb-local + + - name: Load sample + if: ${{ startsWith(github.ref, 'test') }} + run: python3 tests/example_load_data.py - #- name: Load sample - # run: python3 tests/example_load_data.py + - name: Test with pytest + if: ${{ startsWith(github.ref, 'test') }} + run: pytest tests/test_api.py - #- name: Test with pytest - # run: pytest tests/test_api.py + ## Set environment variables + - name: Configure Initial YAML file and environment variables + run: | + echo "THE_VERSION=${{ env.software_version }}" >> $GITHUB_ENV; + echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV; + GITHUB_REF_READABLE="${GITHUB_REF//\//-}" + echo "GITHUB_REF_READABLE=${GITHUB_REF_READABLE}" >> $GITHUB_ENV + echo "THE_ENV=sit" >> $GITHUB_ENV + echo "TARGET_ENV_UPPERCASE=SIT" >> $GITHUB_ENV + + # Setup Node to install and test + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: 14 + + - name: NPM install & NPM Lint + run: + npm install + npm run lint # Setup Terraform to Deploy - name: Configure AWS Credentials as Environment Variables run: echo "AWS_ACCESS_KEY_ID=${{ secrets[format('AWS_ACCESS_KEY_ID_SERVICES_{0}', env.TARGET_ENV_UPPERCASE)] }}" >> $GITHUB_ENV | - echo "AWS_SECRET_ACCESS_KEY=${{ secrets[format('AWS_SECRET_ACCESS_KEY_SERVICES_{0}', env.TARGET_ENV_UPPERCASE)] }}" >> $GITHUB_ENV + echo "AWS_SECRET_ACCESS_KEY=${{ secrets[format('AWS_SECRET_ACCESS_KEY_SERVICES_{0}', env.TARGET_ENV_UPPERCASE)] }}" >> $GITHUB_ENV - name: Validate AWS Credentials uses: aws-actions/configure-aws-credentials@v1 @@ -209,20 +224,21 @@ jobs: path: dist/*.zip - name: Deploy Terraform - #if: | - # github.ref == 'refs/heads/develop' || - # github.ref == 'refs/heads/main' || - # startsWith(github.ref, 'refs/heads/release') || - # github.event.head_commit.message == '/deploy sit' || - # github.event.head_commit.message == '/deploy uat' + if: | + github.ref == 'refs/heads/develop' || + github.ref == 'refs/heads/main' || + startsWith(github.ref, 'refs/heads/release') || + github.event.head_commit.message == '/deploy sit' || + github.event.head_commit.message == '/deploy uat' working-directory: terraform/ env: - AWS_ACCESS_KEY_ID: ${{ secrets[format('AWS_ACCESS_KEY_ID_SERVICES_{0}', env.TARGET_ENV_UPPERCASE)] }} - AWS_SECRET_ACCESS_KEY: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_SERVICES_{0}', env.TARGET_ENV_UPPERCASE)] }} - AWS_DEFAULT_REGION: us-west-2 + AWS_ACCESS_KEY_ID: ${{ secrets[format('AWS_ACCESS_KEY_ID_SERVICES_{0}', env.TARGET_ENV_UPPERCASE)] }} + AWS_SECRET_ACCESS_KEY: ${{ secrets[format('AWS_SECRET_ACCESS_KEY_SERVICES_{0}', env.TARGET_ENV_UPPERCASE)] }} + AWS_DEFAULT_REGION: us-west-2 run: | source bin/config.sh ${{ env.THE_ENV }} - #terraform init -reconfigure -backend-config="bucket=podaac-services-${{ env.THE_ENV }}-terraform" -backend-config="region=us-west-2" - terraform plan -var-file=tfvars/"${{ env.THE_ENV }}".tfvars -var="app_version=${{ env.THE_VERSION }}" -out="tfplan" - terraform apply -auto-approve tfplan \ No newline at end of file + + terraform init -reconfigure -backend-config="bucket=podaac-services-${{ env.THE_ENV }}-terraform" -backend-config="region=us-west-2" + terraform plan -var-file=tfvars/${{ env.THE_ENV }}.tfvars -var="app_version=${{ env.THE_VERSION }}" -out="tfplan" + terraform apply -auto-approve tfplan