Merge pull request #159 from BackendsByMTT/dev-g #54
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 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: 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 "TrippyRahul" | |
git config --global user.email "rahulrawat.trippybug@gmail.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: main | |
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 |