skip to Main Content

I have 3 repos, A,B and C. A is the parent. In the A repo i have a github action, see below.
Package B and C are in package A.

Is it possible and how can i achive to run npm test for repo B en C BEFORE i run the test for repo A?

on:
  push:
    tags:
      - '*'
name: 🚀 Deploy website on create tag
jobs:
  web-deploy:
    name: 🎉 Deploy
    runs-on: ubuntu-latest
    steps:
    - name: 🚚 Get latest code
      uses: actions/checkout@v2

    - name: Use Node.js 14
      uses: actions/setup-node@v2
      with:
        node-version: '14'
        registry-url: 'https://registry.npmjs.org'
        scope: '@xxxxxx'
    - name: 🔨 NPM install en build prod
      run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
    - run: npm ci
    - run: npm run build
    - run: npm run test

    - name: Copy public dir to production
      uses: appleboy/scp-action@master
      with:
        host:  ${{ secrets.HOST }}
        username: ${{ secrets.SSH_USER }}
        key: ${{secrets.SSH_PRIVATE_KEY}}
        port: ${{secrets.SSH_PORT}}
        command_timeout: 30s
        source: "./public"
        target: "/var/www/html/"

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution.

    on:
      push
    name: 🚀 Deploy website on create tag
    jobs:
      web-deploy:
        name: 🎉 B
        runs-on: ubuntu-latest
        steps:
          - name: Check out my other private repo
            uses: actions/checkout@master
            with:
              repository: 'bbb/bbb'
              token: ${{ secrets.PAT }}
          - name: 🔨 NPM install en build prod
          - run: npm ci
          - run: npm run build
          - run: npm run test
    
      web-deploy:
        name: 🎉 C
        runs-on: ubuntu-latest
        steps:
          - name: Check out my other private repo
            uses: actions/checkout@master
            with:
              repository: 'ccc/ccc'
              token: ${{ secrets.PAT }}
          - name: 🔨 NPM install en build prod
          - run: npm ci
          - run: npm run build
          - run: npm run test
    

    And the rest...


  2. You could define a job for each testing step A,B and C described here. In the code below B and C are each in their own working-directory (/B and /C) within the repository A.
    B and C run in parallel. After BOTH have completed successfully job A is run. (Based on your code, not tested)

    jobs:
      B:
        name: Do job B
        runs-on: ubuntu-latest
        defaults:
          run:
            working-directory: 'B' 
        steps:
        - name: 🚚 Get latest code
          uses: actions/checkout@v2
        - name: Use Node.js 14
          uses: actions/setup-node@v2
          with:
            node-version: '14'
            registry-url: 'https://registry.npmjs.org'
            scope: '@xxxxxx'
        - name: 🔨 NPM install en build prod
          run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
        - run: npm ci
        - run: npm run build
        - run: npm run test
    
      C:
        name: Do job C
        runs-on: ubuntu-latest
        defaults:
          run:
            working-directory: 'C'
        steps:
          - name: 🚚 Get latest code
            uses: actions/checkout@v2
          - name: Use Node.js 14
            uses: actions/setup-node@v2
            with:
              node-version: '14'
              registry-url: 'https://registry.npmjs.org'
              scope: '@xxxxxx'
          - name: 🔨 NPM install en build prod
            run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
          - run: npm ci
          - run: npm run build
          - run: npm run test
    
      A:
        name: Do job A
        needs: [B, C]
        runs-on: ubuntu-latest
        steps:
          - name: 🚚 Get latest code
            uses: actions/checkout@v2
          - name: Use Node.js 14
            uses: actions/setup-node@v2
            with:
              node-version: '14'
              registry-url: 'https://registry.npmjs.org'
              scope: '@xxxxxx'
          - name: 🔨 NPM install en build prod
            run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > .npmrc
          - run: npm ci
          - run: npm run build
          - run: npm run test
          - name: Copy public dir to production
            uses: appleboy/scp-action@master
            with:
              host: ${{ secrets.HOST }}
              username: ${{ secrets.SSH_USER }}
              key: ${{secrets.SSH_PRIVATE_KEY}}
              port: ${{secrets.SSH_PORT}}
              command_timeout: 30s
              source: "./public"
              target: "/var/www/html/"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search