From 158a635f95924fa28d35a9fe41b355129be5575c Mon Sep 17 00:00:00 2001 From: Vincent Muriuki Date: Mon, 17 Feb 2025 12:15:31 +0300 Subject: [PATCH] Add CI/CD workflow for Node.js application - Create GitHub Actions workflow (.github/workflows/ci.yml) to automate CI/CD processes. - Configure jobs for both building and publishing the application. - Set up testing against multiple Node.js versions (18, 20). - Include steps to install dependencies and publish to npm registry upon release. - Conditional publishing based on main branch pushes. - Add placeholders for linting and testing steps for future integration. --- .github/workflows/ci.yml | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c2643d3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,58 @@ +name: Node CI/CD + +on: + push: + branches: [main] + pull_request: + branches: [main] + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18, 20] # Test against multiple Node versions + steps: + - uses: actions/checkout@v2 + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Dependencies + run: npm install + + # - name: Run Lint + # run: npm run lint + + # - name: Run Tests + # run: npm test + + publish: + needs: build + runs-on: ubuntu-latest + # if: github.event_name == 'release' + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v2 + + - name: Set up Node.js for Publishing + uses: actions/setup-node@v3 + with: + node-version: '20' + registry-url: 'https://registry.npmjs.org' + + - name: Install Dependencies + run: npm install + + # Uncomment if you have a build step + # - name: Build Package + # run: npm run build + + - name: Publish Package + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npm publish