|
| 1 | +name: CI Workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - '**' |
| 10 | + |
| 11 | +jobs: |
| 12 | + setup_and_test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + matrix: |
| 16 | + node-version: ['18.x', '20.x'] |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v2 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Set up Node.js |
| 24 | + uses: actions/setup-node@v2 |
| 25 | + with: |
| 26 | + node-version: ${{ matrix.node-version }} |
| 27 | + cache: 'yarn' |
| 28 | + |
| 29 | + - name: Check Node.js version |
| 30 | + run: node -v |
| 31 | + |
| 32 | + - name: Install dependencies |
| 33 | + run: yarn install --frozen-lockfile |
| 34 | + |
| 35 | + - name: Lint code |
| 36 | + run: yarn lint:all |
| 37 | + |
| 38 | + - name: Build projects |
| 39 | + run: yarn build:all |
| 40 | + |
| 41 | + - name: Test projects |
| 42 | + run: yarn test:all |
| 43 | + |
| 44 | + validate_commit_messages: |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v2 |
| 48 | + with: |
| 49 | + fetch-depth: 0 |
| 50 | + - name: Ensure full git history |
| 51 | + run: | |
| 52 | + if [ -f $(git rev-parse --git-dir)/shallow ]; then |
| 53 | + git fetch --prune --unshallow |
| 54 | + else |
| 55 | + git fetch --prune origin |
| 56 | + fi |
| 57 | + - name: Validate Commit Messages |
| 58 | + run: | |
| 59 | + commit_messages=$(git log --format=%B origin/main..HEAD) |
| 60 | + echo "Checking commit messages: $commit_messages" |
| 61 | + IFS=$'\n' |
| 62 | + for message in $commit_messages; do |
| 63 | + if [[ "$message" =~ ^Merge ]]; then |
| 64 | + echo "Skipping merge commit: $message" |
| 65 | + elif ! echo "$message" | grep -Pq '^(ADD:|FIX:|DEL:|UPD:) .+'; then |
| 66 | + echo "Invalid commit message: '$message'" |
| 67 | + echo "Commit messages must start with ADD:, FIX:, DEL:, or UPD:" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + done |
| 71 | + echo "All commit messages adhere to the format." |
| 72 | +
|
| 73 | + validate_branch_names: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v2 |
| 77 | + - name: Validate Branch Names |
| 78 | + run: | |
| 79 | + if [ "${{ github.event_name }}" == "pull_request" ]; then |
| 80 | + if [ -z "${{ github.head_ref }}" ]; then |
| 81 | + branch_name=$(echo $GITHUB_REF | sed -n 's/refs\/heads\/\([^/]*\)/\1/p') |
| 82 | + echo "Extracted branch name from ref: $branch_name" |
| 83 | + else |
| 84 | + branch_name=${{ github.head_ref }} |
| 85 | + echo "Running in a fork pull request with branch: $branch_name" |
| 86 | + fi |
| 87 | + else |
| 88 | + branch_name=$(git rev-parse --abbrev-ref HEAD) |
| 89 | + echo "Current branch: $branch_name" |
| 90 | + fi |
| 91 | + if ! echo "$branch_name" | grep -Eq '^(main|feature/.+|hotfix/.+)$'; then |
| 92 | + echo "Error: Branch name $branch_name does not fit the naming convention." |
| 93 | + exit 1 |
| 94 | + fi |
| 95 | + echo "Branch name fits the naming convention." |
0 commit comments