Skip to content

correct env

correct env #40

Workflow file for this run

name: Build & Publish
on:
push:
branches:
- main # # Trigger workflow on pushes to 'main' (Production)
- uat # Trigger workflow on pushes to 'uat' (UAT)
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
# Step 3: Install dependencies (npm or yarn based on your setup)
- name: Install dependencies
run: npm install
# Step 4: Run all tests
- name: Run all tests
run: npm run test
# Step 5: Run Unit Tests
- name: Run Unit Tests
run: npm run test:unit
# Step 6: Run Integration Tests
- name: Run Integration Tests
run: npm run test:integration
# Step 7: Run Component Tests
- name: Run Component Tests
run: npm run test:component
# Step 8: Run Contract Tests
- name: Run Contract Tests
run: npm run test:contract
# Step 9: Set up Docker
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Step 10: Log in to Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Step 11: Determine the environment based on the branch and set environment variables
- name: Determine environment
id: env-check
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
echo "ENVIRONMENT=prod" >> $GITHUB_ENV
echo "DATABASE_URL=${{ secrets.PROD_DB_URL }}" >> $GITHUB_ENV
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> $GITHUB_ENV
echo "HTTP_PORT=${{ secrets.HTTP_PORT }}" >> $GITHUB_ENV
elif [[ "${{ github.ref }}" == "refs/heads/uat" ]]; then
echo "ENVIRONMENT=uat" >> $GITHUB_ENV
echo "DATABASE_URL=${{ secrets.UAT_DB_URL }}" >> $GITHUB_ENV
echo "JWT_SECRET=${{ secrets.JWT_SECRET }}" >> $GITHUB_ENV
echo "HTTP_PORT=${{ secrets.HTTP_PORT }}" >> $GITHUB_ENV
else
echo "Unknown branch. Exiting."
exit 1
fi
# Step 12: Build the Docker image with the appropriate image tag
- name: Build Docker image
run: |
IMAGE_TAG="${{ secrets.DOCKERHUB_USERNAME }}/tasker-api:${{ env.ENVIRONMENT }}"
docker build --build-arg DATABASE_URL=${{ env.DATABASE_URL }} --build-arg HTTP_PORT=${{ env.HTTP_PORT }} --build-arg JWT_SECRET=${{ env.JWT_SECRET }} -t $IMAGE_TAG .
echo "Built image with tag: $IMAGE_TAG"
# Step 13: Push the Docker image to Docker Hub
- name: Push Docker image to Docker Hub
run: |
IMAGE_TAG="${{ secrets.DOCKERHUB_USERNAME }}/tasker-api:${{ env.ENVIRONMENT }}"
docker push $IMAGE_TAG
# Optionally, add latest tag for main branch
- name: Tag Docker image as latest (main branch only)
if: github.ref == 'refs/heads/main'
run: |
docker tag ${{ secrets.DOCKERHUB_USERNAME }}/tasker-api:prod ${{ secrets.DOCKERHUB_USERNAME }}/tasker-api:latest
docker push ${{ secrets.DOCKERHUB_USERNAME }}/tasker-api:latest