|
1 |
| -# automate-github-actions-using-rest-api |
2 |
| -This is a sample node.js project for which github actions cicd workflow file is automated using the github rest apis |
| 1 | +# Automate Github Actions Using GitHub REST API |
| 2 | +This project is a demonstration of automating a GitHub Actions CI/CD pipeline using the GitHub REST API, integrated into a simple Node.js web application. The application includes a button to trigger the CI/CD pipeline directly from the frontend, providing an interactive way to manage the workflow. |
3 | 3 |
|
| 4 | +## Features |
| 5 | +- **GitHub Actions Integration :** Uses GitHub REST API to trigger a workflow directly from the application. |
| 6 | +- **Interactive UI :** A button on the web interface initiates the CI/CD pipeline. |
| 7 | +- **REST API Usage :** Demonstrates how to call the GitHub REST API from within a Node.js server. |
| 8 | +- **CORS Enabled :** Ensures the frontend can communicate with the backend on the same server. |
4 | 9 |
|
5 |
| -- `server.js`: This file will serve an HTML page and include an endpoint to trigger the GitHub Actions workflow. |
| 10 | +## Project Structure |
| 11 | +```bash |
| 12 | +demo-ci-cd-app/ |
| 13 | +├── .env # Environment variables (GitHub token) |
| 14 | +├── .github/ |
| 15 | +│ └── workflows/ |
| 16 | +│ └── main.yml # GitHub Actions workflow file |
| 17 | +├── public/ |
| 18 | +│ └── index.html # Frontend HTML file |
| 19 | +├── server.js # Node.js server file |
| 20 | +├── package.json # Node.js project configuration |
| 21 | +└── README.md # Project documentation |
| 22 | +└── node_modules # Project dependencies |
| 23 | +``` |
| 24 | + |
| 25 | +## Installation |
| 26 | +### Step 1: Clone the Repository |
| 27 | + |
| 28 | +```bash |
| 29 | +git clone https://github.com/YOUR_USERNAME/demo-ci-cd-app.git |
| 30 | +cd automate-github-actions-using-rest-api |
| 31 | +``` |
| 32 | + |
| 33 | +### Step 2: Install Dependencies |
| 34 | + |
| 35 | +```bash |
| 36 | +npm install |
| 37 | +``` |
| 38 | + |
| 39 | +### Step 3: Set Up Environment Variable |
| 40 | +Create a .env file in the root directory: |
| 41 | + |
| 42 | +```bash |
| 43 | +GITHUB_TOKEN=your_personal_access_token |
| 44 | +# Replace your_personal_access_token with your GitHub Personal Access Token (with repo and workflow permissions). |
| 45 | +``` |
| 46 | + |
| 47 | +### Step 4: Configure GitHub Actions Workflow: |
| 48 | + |
| 49 | +Go to the `.github/workflows/main.yml` file and ensure it has the following setup: |
| 50 | + |
| 51 | +```yaml |
| 52 | +name: CI/CD Pipeline |
| 53 | + |
| 54 | +on: |
| 55 | + workflow_dispatch: |
| 56 | + push: |
| 57 | + branches: |
| 58 | + - main |
| 59 | + |
| 60 | +jobs: |
| 61 | + build: |
| 62 | + runs-on: ubuntu-latest |
| 63 | + |
| 64 | + steps: |
| 65 | + - name: Checkout Code |
| 66 | + uses: actions/checkout@v2 |
| 67 | + |
| 68 | + - name: Display Message |
| 69 | + run: echo "CI/CD Pipeline is triggered successfully!" |
| 70 | +``` |
| 71 | +
|
| 72 | +### Step 5: Start the Server: |
| 73 | +
|
| 74 | +```bash |
| 75 | +node server.js |
| 76 | +``` |
| 77 | + |
| 78 | +### Access the Application |
| 79 | + |
| 80 | +- Open your browser and go to http://localhost:3000. |
| 81 | +- Click on the Trigger CI/CD Pipeline button. This will make a POST request to the GitHub API to start the workflow. |
0 commit comments