diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2e259b3..983700c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -3,11 +3,99 @@ on: push: branches: - develop + pull_request: + branches: + - develop jobs: - fake_job: + test_lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - run: echo DONE \ No newline at end of file + - uses: actions/setup-node@v1 + - run: npm ci + - name: Making sure 'npm run lint' and 'npm run format' does not changes anything. + run: | + sleep 15 + npm run lint:check + npm run format:check + test_node: + runs-on: ${{ matrix.os }} + needs: test_lint + strategy: + matrix: + node: [ '14', '13', '12' ] + os: [ windows-latest, ubuntu-latest ] + name: Test with Node v${{ matrix.node }} on ${{ matrix.os }} + steps: + - name: Tell if project is using npm or yarn + id: _1 + uses: garronej/github_actions_toolkit@v1.11 + with: + action_name: tell_if_project_uses_npm_or_yarn + owner: ${{github.repository_owner}} + repo: ${{github.event.repository.name}} + branch: ${{github.ref}} + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + - if: steps._1.npm_or_yarn == 'yarn' + run: | + yarn install --frozen-lockfile + yarn run build + yarn run test + - if: steps._1.npm_or_yarn == 'npm' + run: | + npm ci + npm run build + npm run test + trigger_publish: + name: Trigger publish.yaml workflow if package.json version updated ( and secrets.PAT is set ). + runs-on: ubuntu-latest + env: + PAT: ${{secrets.PAT}} + if: github.event_name == 'push' && github.event.head_commit.author.name != 'ts_ci' + needs: test_node + steps: + + - name: Get version on latest + id: v_latest + uses: garronej/github_actions_toolkit@v1.11 + with: + action_name: get_package_json_version + owner: ${{github.repository_owner}} + repo: ${{github.event.repository.name}} + branch: latest + compare_to_version: '0.0.0' + + - name: Get version on develop + id: v_develop + uses: garronej/github_actions_toolkit@v1.11 + with: + action_name: get_package_json_version + owner: ${{github.repository_owner}} + repo: ${{github.event.repository.name}} + branch: ${{ github.sha }} + compare_to_version: ${{steps.v_latest.outputs.version || '0.0.0'}} + + - name: 'Trigger the ''publish'' workflow' + if: ${{ !!env.PAT && steps.v_develop.outputs.compare_result == '1' }} + uses: garronej/github_actions_toolkit@v1.11 + env: + GITHUB_TOKEN: ${{ secrets.PAT }} + with: + action_name: dispatch_event + owner: ${{github.repository_owner}} + repo: ${{github.event.repository.name}} + event_type: publish + client_payload_json: | + ${{ + format( + '{{"from_version":"{0}","to_version":"{1}","repo":"{2}"}}', + steps.v_latest.outputs.version, + steps.v_develop.outputs.version, + github.event.repository.name + ) + }} \ No newline at end of file diff --git a/workflows/publish.yaml b/.github/workflows/publish.yaml similarity index 100% rename from workflows/publish.yaml rename to .github/workflows/publish.yaml diff --git a/.github/workflows/template_initialization.yaml b/.github/workflows/template_initialization.yaml index 499d22d..f086a59 100644 --- a/.github/workflows/template_initialization.yaml +++ b/.github/workflows/template_initialization.yaml @@ -33,7 +33,6 @@ jobs: - run: | mv README.template.md README.md mv LICENSE.template LICENSE - mv workflows/*.yaml .github/workflows/ && rm -r workflows - name : String replace id: id2 uses: garronej/github_actions_toolkit@v1.9 diff --git a/README.md b/README.md index 28d66a7..d58dd7d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- +

A template to assist you in creating and publishing TypeScript modules on NPM diff --git a/workflows/ci.yaml b/workflows/ci.yaml deleted file mode 100644 index e965aa7..0000000 --- a/workflows/ci.yaml +++ /dev/null @@ -1,100 +0,0 @@ -name: ci -on: - push: - branches: - - develop - pull_request: - branches: - - develop - -jobs: - - test_lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - run: npm ci - - name: Making sure 'npm run lint' and 'npm run format' does not changes anything. - run: | - npm run lint:check - npm run format:check - test_node: - runs-on: ${{ matrix.os }} - needs: test_lint - strategy: - matrix: - node: [ '14', '13', '12' ] - os: [ windows-latest, ubuntu-latest ] - name: Test with Node v${{ matrix.node }} on ${{ matrix.os }} - steps: - - name: Tell if project is using npm or yarn - id: _1 - uses: garronej/github_actions_toolkit@v1.11 - with: - action_name: tell_if_project_uses_npm_or_yarn - owner: ${{github.repository_owner}} - repo: ${{github.event.repository.name}} - branch: ${{github.ref}} - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node }} - - if: steps._1.npm_or_yarn == 'yarn' - run: | - yarn install --frozen-lockfile - yarn run build - yarn run test - - if: steps._1.npm_or_yarn == 'npm' - run: | - npm ci - npm run build - npm run test - trigger_publish: - name: Trigger publish.yaml workflow if package.json version updated ( and secrets.PAT is set ). - runs-on: ubuntu-latest - env: - PAT: ${{secrets.PAT}} - if: github.event_name == 'push' && github.event.head_commit.author.name != 'ts_ci' - needs: test_node - steps: - - - name: Get version on latest - id: v_latest - uses: garronej/github_actions_toolkit@v1.11 - with: - action_name: get_package_json_version - owner: ${{github.repository_owner}} - repo: ${{github.event.repository.name}} - branch: latest - compare_to_version: '0.0.0' - - - name: Get version on develop - id: v_develop - uses: garronej/github_actions_toolkit@v1.11 - with: - action_name: get_package_json_version - owner: ${{github.repository_owner}} - repo: ${{github.event.repository.name}} - branch: ${{ github.sha }} - compare_to_version: ${{steps.v_latest.outputs.version || '0.0.0'}} - - - name: 'Trigger the ''publish'' workflow' - if: ${{ !!env.PAT && steps.v_develop.outputs.compare_result == '1' }} - uses: garronej/github_actions_toolkit@v1.11 - env: - GITHUB_TOKEN: ${{ secrets.PAT }} - with: - action_name: dispatch_event - owner: ${{github.repository_owner}} - repo: ${{github.event.repository.name}} - event_type: publish - client_payload_json: | - ${{ - format( - '{{"from_version":"{0}","to_version":"{1}","repo":"{2}"}}', - steps.v_latest.outputs.version, - steps.v_develop.outputs.version, - github.event.repository.name - ) - }} \ No newline at end of file