name: CI/CD on: push: branches: - '**' jobs: # runs on branch pushes only ci: name: Run Tests if: startsWith(github.ref, 'refs/heads') runs-on: ubuntu-18.04 steps: - name: Checkout uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: 12 - name: Install dependencies run: npm ci - name: happy-path id: happy_path uses: ./ with: timeout_minutes: 1 max_attempts: 2 command: npm -v - uses: nick-invision/assert-action@v1 with: expected: true actual: ${{ steps.happy_path.outputs.total_attempts == '1' && steps.happy_path.outputs.exit_code == '0' }} - name: sad-path (retry_wait_seconds) id: sad_path_wait_sec uses: ./ continue-on-error: true with: timeout_minutes: 1 max_attempts: 3 retry_wait_seconds: 15 command: npm install this-isnt-a-real-package-name-zzz - uses: nick-invision/assert-action@v1 with: expected: 3 actual: ${{ steps.sad_path_wait_sec.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: expected: failure actual: ${{ steps.sad_path_wait_sec.outcome }} - uses: nick-invision/assert-action@v1 with: expected: 'Final attempt failed' actual: ${{ steps.sad_path_wait_sec.outputs.exit_error }} comparison: contains - name: sad-path (error) id: sad_path_error uses: ./ continue-on-error: true with: timeout_minutes: 1 max_attempts: 2 command: node -e "process.exit(1)" - uses: nick-invision/assert-action@v1 with: expected: 2 actual: ${{ steps.sad_path_error.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: expected: failure actual: ${{ steps.sad_path_error.outcome }} - name: retry_on (timeout) fails early if nonzero encountered id: retry_on_timeout_fail uses: ./ continue-on-error: true with: timeout_minutes: 1 max_attempts: 3 retry_on: timeout command: node -e "process.exit(2)" - uses: nick-invision/assert-action@v1 with: expected: 1 actual: ${{ steps.retry_on_timeout_fail.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: expected: failure actual: ${{ steps.retry_on_timeout_fail.outcome }} - uses: nick-invision/assert-action@v1 with: expected: 2 actual: ${{ steps.retry_on_timeout_fail.outputs.exit_code }} - name: retry_on (nonzero) id: retry_on_nonzero uses: ./ continue-on-error: true with: timeout_minutes: 1 max_attempts: 2 retry_on: nonzero command: node -e "process.exit(2)" - uses: nick-invision/assert-action@v1 with: expected: 2 actual: ${{ steps.retry_on_nonzero.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: expected: failure actual: ${{ steps.retry_on_nonzero.outcome }} - uses: nick-invision/assert-action@v1 with: expected: 2 actual: ${{ steps.retry_on_nonzero.outputs.exit_code }} # timeout tests (takes longer to run so run last) - name: sad-path (timeout) id: sad_path_timeout uses: ./ continue-on-error: true with: timeout_seconds: 15 max_attempts: 2 command: node -e "(async()=>await new Promise(r => setTimeout(r, 120000)))()" - uses: nick-invision/assert-action@v1 with: expected: 2 actual: ${{ steps.sad_path_timeout.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: expected: failure actual: ${{ steps.sad_path_timeout.outcome }} - name: retry_on (timeout) id: retry_on_timeout uses: ./ continue-on-error: true with: timeout_seconds: 15 max_attempts: 2 retry_on: timeout command: node -e "(async()=>await new Promise(r => setTimeout(r, 120000)))()" - uses: nick-invision/assert-action@v1 with: expected: 2 actual: ${{ steps.retry_on_timeout.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: expected: failure actual: ${{ steps.retry_on_timeout.outcome }} - name: retry_on (nonzero) fails early if timeout encountered id: retry_on_nonzero_fail uses: ./ continue-on-error: true with: timeout_seconds: 15 max_attempts: 2 retry_on: nonzero command: node -e "(async()=>await new Promise(r => setTimeout(r, 120000)))()" - uses: nick-invision/assert-action@v1 with: expected: 1 actual: ${{ steps.retry_on_nonzero_fail.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: expected: failure actual: ${{ steps.retry_on_nonzero_fail.outcome }} - uses: nick-invision/assert-action@v1 with: expected: 1 actual: ${{ steps.retry_on_nonzero_fail.outputs.exit_code }} - name: sad-path (timeout minutes) id: sad_path_timeout_minutes uses: ./ continue-on-error: true with: timeout_minutes: 1 max_attempts: 2 command: node -e "(async()=>await new Promise(r => setTimeout(r, 120000)))()" - uses: nick-invision/assert-action@v1 with: expected: 2 actual: ${{ steps.sad_path_timeout.outputs.total_attempts }} - uses: nick-invision/assert-action@v1 with: expected: failure actual: ${{ steps.sad_path_timeout.outcome }} # runs on push to master only cd: name: Publish Action needs: ci if: github.ref == 'refs/heads/master' runs-on: ubuntu-18.04 steps: - name: Checkout uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: 12 - name: Install dependencies run: npm ci - name: Release id: semantic uses: cycjimmy/semantic-release-action@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Tag run: git tag -f v${MAJOR_VERSION} && git push -f origin v${MAJOR_VERSION} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} MAJOR_VERSION: ${{ steps.semantic.outputs.new_release_major_version }}