Skip to content

Update main.yml

Update main.yml #6

Workflow file for this run

name: Build and Deploy
on:
push:
branches:
- "dev"
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: dev
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install Dependencies
run: npm install
- name: Build
run: npm run build
- name: Update package.json in Main
env:
GITHUB_TOKEN: ${{ secrets.G_TOKEN }}
run: |
git config --global user.name "Prathm"
git config --global user.email "prathm@123.com"
git checkout main
cp package.json ../package.json
git add ../package.json
git commit -m "update package.json"
git push --set-upstream origin main
- name: Upload Build Artifacts
uses: actions/upload-artifact@v3
with:
name: artifact
path: ./dist/**/*.js
- name: Commit and Push Build Artifacts
env:
GITHUB_TOKEN: ${{ secrets.G_TOKEN }}
run: |
git config advice.addIgnoredFile false
git rev-parse --abbrev-ref HEAD
git config --global user.name "Prathm"
git config --global user.email "prathm@123.com"
git checkout -b build-artifacts
git add -f ./dist
git commit -m 'added: build artifacts'
git push --set-upstream origin build-artifacts
create_pull_request:
needs: build
runs-on: ubuntu-latest
outputs:
pull_request_number: ${{ steps.create_pr.outputs.pull-request-number }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download Build Artifacts
uses: actions/download-artifact@v3
with:
name: artifact
- name: List Downloaded Artifacts
run: ls -l
- name: Create Pull Request
id: create_pr
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.G_TOKEN }}
commit-message: "added: build artifacts"
branch: build-artifacts
base: dev-build
title: "Add build artifacts"
body: "This pull request contains the build artifacts."
labels: "auto-approve"
merge_pull_request:
needs: create_pull_request
runs-on: ubuntu-latest
steps:
- name: Merge Pull Request
run: |
PR_NUMBER="${{ needs.create_pull_request.outputs.pull_request_number }}"
curl -X PUT \
-H "Authorization: token ${{ secrets.G_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/pulls/${PR_NUMBER}/merge
cleanup:
if: ${{ always() }}
needs: [merge_pull_request, build]
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Delete Build Artifacts Branch
env:
GITHUB_TOKEN: ${{ secrets.G_TOKEN }}
run: |
git push origin --delete build-artifacts