Created
July 13, 2024 21:24
-
-
Save kavicastelo/bd2d807c9f436b755fa81eafc6b9d1d4 to your computer and use it in GitHub Desktop.
angular and springboot project build, test and deploying using one single workflow with breakdowns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, Test, and Deploy | |
on: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
setup-environment: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create environment directory | |
run: mkdir -p client/src/environments | |
- name: Setup environment variables for production | |
run: | | |
echo "${{ secrets.ENV_FILE_PROD_CONTENT }}" > client/src/environments/environment.ts | |
echo "Production Environment File:" | |
cat client/src/environments/environment.ts | |
- name: Setup environment variables for development | |
run: | | |
echo "${{ secrets.ENV_FILE_DEV_CONTENT }}" > client/src/environments/environment.development.ts | |
echo "Development Environment File:" | |
cat client/src/environments/environment.development.ts | |
build-frontend: | |
runs-on: ubuntu-latest | |
needs: setup-environment | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create environment directory | |
run: mkdir -p client/src/environments | |
- name: Setup environment variables for production | |
run: echo "${{ secrets.ENV_FILE_PROD_CONTENT }}" > client/src/environments/environment.ts | |
- name: Setup environment variables for development | |
run: echo "${{ secrets.ENV_FILE_DEV_CONTENT }}" > client/src/environments/environment.development.ts | |
- name: Install dependencies | |
run: | | |
cd client | |
npm install --force | |
- name: Build frontend | |
run: | | |
cd client | |
npm run build -- --configuration production --output-path=dist/client | |
build-backend: | |
runs-on: ubuntu-latest | |
needs: setup-environment | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Java | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: Setup environment variables | |
run: echo "FAKE_ENV_VARIABLES" > .env | |
- name: Build backend | |
run: | | |
chmod +x ./mvnw | |
./mvnw clean package -DskipTests | |
test-frontend: | |
runs-on: ubuntu-latest | |
needs: build-frontend | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create environment directory | |
run: mkdir -p client/src/environments | |
- name: Setup environment variables for production | |
run: echo "${{ secrets.ENV_FILE_PROD_CONTENT }}" > client/src/environments/environment.ts | |
- name: Setup environment variables for development | |
run: echo "${{ secrets.ENV_FILE_DEV_CONTENT }}" > client/src/environments/environment.development.ts | |
- name: Install dependencies | |
run: | | |
cd client | |
npm install --force | |
- name: Run frontend tests | |
run: | | |
cd client | |
npm run test -- --watch=false --no-progress --browsers=ChromeHeadless | |
test-backend: | |
runs-on: ubuntu-latest | |
needs: build-backend | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Java | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: Run backend tests | |
run: | | |
chmod +x ./mvnw | |
./mvnw test | |
e2e-test: | |
runs-on: ubuntu-latest | |
needs: [build-frontend, test-frontend, test-backend] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Create environment directory | |
run: mkdir -p client/src/environments | |
- name: Setup environment variables for production | |
run: echo "${{ secrets.ENV_FILE_PROD_CONTENT }}" > client/src/environments/environment.ts | |
- name: Setup environment variables for development | |
run: echo "${{ secrets.ENV_FILE_DEV_CONTENT }}" > client/src/environments/environment.development.ts | |
- name: Run Cypress tests | |
run: | | |
cd client | |
npx cypress run --headless | grep -v 'org.freedesktop.UPower' | |
deploy-frontend: | |
runs-on: ubuntu-latest | |
needs: [e2e-test] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' | |
- name: Create environment directory | |
run: mkdir -p client/src/environments | |
- name: Setup environment variables for production | |
run: echo "${{ secrets.ENV_FILE_PROD_CONTENT }}" > client/src/environments/environment.ts | |
- name: Setup environment variables for development | |
run: echo "${{ secrets.ENV_FILE_DEV_CONTENT }}" > client/src/environments/environment.development.ts | |
- name: Install dependencies | |
working-directory: client | |
run: npm install | |
- name: Install Netlify CLI | |
working-directory: client | |
run: npm install netlify-cli --save-dev | |
- name: Build project | |
working-directory: client | |
run: npm run build -- --configuration production --output-path=dist/client | |
- name: Deploy to Netlify | |
working-directory: client | |
run: npx netlify deploy --dir=dist/client --prod | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
deploy-backend: | |
runs-on: ubuntu-latest | |
needs: deploy-frontend | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup Java | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: Build backend | |
run: | | |
chmod +x ./mvnw | |
./mvnw clean package -DskipTests | |
- name: Deploy to Render | |
run: | | |
curl -X POST -H "Accept: application/json" -H "Authorization: Bearer ${{ secrets.RENDER_API_KEY }}" \ | |
-d '{}' \ | |
https://api.render.com/v1/services/YOUR_SERVICE_ID/deploys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment