Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

fix build

fix build #16

Workflow file for this run

# This is the main build pipeline that verifies and publishes the software
name: Build
# Controls when the workflow will run
on:
# Triggers the workflow on push events
push:
branches:
- main
- develop
- 'release/**'
- 'feature/**'
- 'issue/**'
- 'issues/**'
- 'dependabot/**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PROJECT_ NAME: podaac/hydrocron-api
jobs:
# First job in the workflow installs and verifies the software
build:
name: Build, Test, Deploy
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Checkout
- name: Checkout project to build and deploy
uses: actions/checkout@v2
## Read the json file into the environment variables
- name: JSON to variables
uses: actions/checkout@v2
with:
filename: 'package.json'
prefix: project
## Set environment variables
- name: Configure Initial YAML file and environment variables
run: |
echo "THE_VERSION=${{ env.project_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
# Setup docker to build and push images
- name: Log in to the Container registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy Env Override
if: |
github.event.head_commit.message == '/deploy sit' ||
github.event.head_commit.message == '/deploy uat'
run: |
message="${{ github.event.head_commit.message }}"
trimmed_message=${message:1} # Remove leading slash
override_env=$(echo "$trimmed_message" | grep -oE '[^[:space:]]+$')
override_env_upper=$(echo "$trimmed_message" | awk '{print toupper($NF)}')
echo "THE_ENV=${override_env}" >> $GITHUB_ENV
echo "TARGET_ENV_UPPERCASE=${override_env_upper}" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},value=${{ env.THE_VERSION }}
type=raw,value=${{ env.THE_ENV }}
- name: Build and push Docker image
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'
uses: docker/build-push-action@v3
with:
context: .
file: docker/Dockerfile
push: true
pull: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Setup DynamoDB Local
id: setupdb
uses: actions/checkout@v2
with:
dbPath: # undefined by default, if this is undefined inMemory will be used
sharedDb: # undefined by default
delayTransientStatuses: # undefined by default
optimizeDbBeforeStartup: # undefined by default
port: 8000
cors: '*'
- name: Get DynamoDB Item
id: config
uses: actions/checkout@v2
env:
AWS_DEFAULT_REGION: us-west-2
AWS_REGION: us-west-2
AWS_ACCESS_KEY_ID: a
AWS_SECRET_ACCESS_KEY: a
AWS_SESSION_TOKEN: fake_session_token
with:
operation: get
region: us-west-2
table: hydrocron_swot_reaches
key: |
{ key: "reach_id" }
- name: Print item
run: |
echo '${{ steps.config.outputs.item }}'
- name: Print specific field using built-in function
run: |
echo '${{ steps.config.outputs.item }}'
- name: Print specific field using jq
run: |
jq '.commit' <<< '${{ steps.config.outputs.item }}'
- name: Test with pytest
id: tests
uses: actions/checkout@v2
run: |
python3 -m pip install --upgrade pip
pip3 install pytest pytest-cov
pip3 install -r requirements.txt
python3 tests/example_load_data.py
pytest tests/test_api.py