create angular github action #9
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 Release Angular Library | |
# Trigger workflow on pull request or push to main | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
# Job 1: Test and build library on pull request | |
test-and-build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: npm install | |
# - name: Run unit tests | |
# run: npm run test projects/ng-inbo -- --no-watch --no-progress --browsers=ChromeHeadless | |
- name: Build library | |
run: npm run build | |
# Job 2: Publish the library to npm on push to main | |
create-pr: | |
runs-on: ubuntu-latest | |
needs: test-and-build # Ensure this job runs after publishing | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
title: "Automated PR for Release" | |
body: "This PR is created automatically after publishing the library." | |
base: main | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
auto-merge: | |
runs-on: ubuntu-latest | |
needs: [create-pr] | |
if: ${{ github.event.pull_request.merged == false && success() }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Merge PR | |
uses: devmasx/merge-branch@master | |
with: | |
type: now | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
target_branch: 'main' | |
publish: | |
if: github.event_name == 'push' && github.ref =='refs/heads/main' && github.repository_owner == 'govflanders' # Triggered | |
needs: auto-merge | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install dependencies | |
run: npm install | |
- name: Build the library | |
run: npm run build --prod | |
- name: Create .npmrc | |
run: echo "@govflanders:registry=https://registry.npmjs.org//registry.npmjs.org/:_authToke=${{ secrets.NPMJS_TOKEN }}" > ~/.npmrc | |
- name: Publish to npm | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPMJS_TOKEN }} | |