aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/ci.yml
blob: da82e7dfb71258d3dd45d61fee333abf252b6eed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# CI build that assembles artifacts and runs tests.
# If validation is successful this workflow releases from the main dev branch.
#
# - skipping CI: add [skip ci] to the commit message
# - skipping release: add [skip release] to the commit message
#
name: CI

on:
  push:
    branches:
      - main
    tags-ignore:
      - v* # release tags are automatically generated after a successful CI build, no need to run CI against them
  pull_request:
    branches:
      - main

jobs:

  #
  # SINGLE-JOB
  #
  verify:
    runs-on:  ubuntu-latest
    if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

    steps:

      - name: 1. Check out code
        uses: actions/checkout@v2 # https://github.com/actions/checkout

      - name: 2. Set up Java 8
        uses: actions/setup-java@v1 # https://github.com/actions/setup-java
        with:
          java-version: 8

      - name: 3. Validate Gradle wrapper
        uses: gradle/wrapper-validation-action@v1 # https://github.com/gradle/wrapper-validation-action

  #
  # Main build job
  #
  build:
    needs: [verify]
    runs-on:  ubuntu-latest

    # Definition of the build matrix
    strategy:
      matrix:
        mock-maker: ['mock-maker-default', 'mock-maker-inline']
        kotlin: ['1.3.50', '1.4.21']
        # Note that the old Travis CI referenced other Kotlin versions: '1.0.7', '1.1.61', '1.2.50'
        # However, those versions of Kotlin don't work with latest Gradle

    steps:

    - name: 1. Check out code
      uses: actions/checkout@v2 # https://github.com/actions/checkout

    - name: 2. Set up Java 8
      uses: actions/setup-java@v1 # https://github.com/actions/setup-java
      with:
        java-version: 8

    - name: 3. Build with Kotlin ${{ matrix.kotlin }} and mock-maker ${{ matrix.mock-maker }}
      run: |
        ops/mockMakerInline.sh
        ./gradlew build
      env:
        KOTLIN_VERSION: ${{ matrix.kotlin }}
        MOCK_MAKER: ${{ matrix.mock-maker }}

  #
  # Release job, only for pushes to the main development branch
  #
  release:
    runs-on: ubuntu-latest
    needs: [build] # build job must pass before we can release

    if: github.event_name == 'push'
        && github.ref == 'refs/heads/main'
        && github.repository == 'mockito/mockito-kotlin'
        && !contains(toJSON(github.event.commits.*.message), '[skip release]')

    steps:

    - name: Check out code
      uses: actions/checkout@v2 # https://github.com/actions/checkout
      with:
        fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci

    - name: Set up Java 8
      uses: actions/setup-java@v1
      with:
        java-version: 8

    - name: Build and release
      run: ./gradlew githubRelease publishToSonatype closeAndReleaseStagingRepository
      env:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
        NEXUS_TOKEN_USER: ${{secrets.NEXUS_TOKEN_USER}}
        NEXUS_TOKEN_PWD: ${{secrets.NEXUS_TOKEN_PWD}}
        PGP_KEY: ${{secrets.PGP_KEY}}
        PGP_PWD: ${{secrets.PGP_PWD}}