aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/auto-merge.yml
blob: 02d33a3e6d5df1f77e5453f829b2edc95ab6d231 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Workflow to cherry-pick changes from main to release branch.

name: auto-merge

on:
  push:
    branches: [ main ]

jobs:
  build-and-test:
    strategy:
      fail-fast: false
      matrix:
        os: [ ubuntu-latest, macos-latest ]

    # The type of runner that the job will run on
    runs-on: ${{ matrix.os }}

    steps:
    # Checkout
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
        ref: 1.0.9-release

    - name: merge commits from main to release branch
      run: |
        # Cherry pick new changes from main, except for version bumps.
        # A commit is a version bump IFF it touches third_party/prebuilt/repo
        DONT_PICK=$(cat <<EOF
        35e1556f6f329714a9d730ea4a7743317535ce1a
        2ed353a57eb379a3b8fa6401cbf3a7abe3da7e8b
        d961b62f71147bfd148d8648bfdf566525a401e7
        fbb02bfeafdb69b876bc6c0bd433fd1ebf4c8150
        EOF
        )
        git config --global user.email "kotlin-symbol-processing@google.com"
        git config --global user.name "KSP Auto Pick"
        MERGE_BASE=$(git merge-base HEAD origin/main)
        CANDIDATES=$(git log --pretty=%H $MERGE_BASE..origin/main)
        PICKED=$(git log $MERGE_BASE..HEAD | sed -n "s/^[ ]*(cherry picked from commit \([a-z0-9]*\))$/\1/p")
        VERSION_BUMPS=$(git log $MERGE_BASE..origin/main --pretty=%H --grep UPDATE_KOTLIN_VERSION)
        AA_COMMITS=$(git log $MERGE_BASE..origin/main --pretty=%H kotlin-analysis-api)
        TO_PICK=$(grep -Fxv -f <(echo "$PICKED"; echo "$VERSION_BUMPS"; echo "$DONT_PICK"; echo "$AA_COMMITS") <(echo "$CANDIDATES") | awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }')
        echo Picking $TO_PICK
        if [ -n "$TO_PICK" ]; then git cherry-pick -x $TO_PICK; fi

    - name: Setup Java 9
      uses: actions/setup-java@v1.4.3
      with:
        java-version: '9'
        java-package: jdk
        architecture: x64
    - name: set JDK_9 environment variable for kotlin compiler
      env:
        ACTIONS_ALLOW_UNSECURE_COMMANDS: true
      run: echo ::set-env name=JDK_9::$(echo $JAVA_HOME)
    - name: Setup Java 11
      uses: actions/setup-java@v1.4.3
      with:
        java-version: '11'
        java-package: jdk
        architecture: x64

    # Build cache
    - name: Cache Gradle Cache
      uses: actions/cache@v2
      with:
        path: ~/.gradle/caches
        key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle.kts') }}-${{ hashFiles('**/gradle.properties') }}
        # An ordered list of keys to use for restoring the cache if no cache hit occurred for key
        restore-keys: |
          ${{ runner.os }}-gradle-
    - name: Cache gradle wrapper
      uses: actions/cache@v2
      with:
        path: ~/.gradle/wrapper
        key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}

    # Check API compatibility
    - name: API compatibility check
      run: ./gradlew :api:checkApi

    # Run ksp generated tests
    - name: test
      run: ./gradlew --stacktrace --info test

    - name: Upload test results
      if: always()
      uses: actions/upload-artifact@v3
      with:
        name: test-reports
        path: |
          compiler-plugin/build/reports
          integration-tests/build/reports
          gradle-plugin/build/reports
          common-util/build/reports

  pick-and-push:
    needs: build-and-test
    runs-on: ubuntu-latest

    steps:
      # Checkout
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
          ref: 1.0.9-release

      - name: merge commits from main to release branch
        run: |
          # Cherry pick new changes from main, except for version bumps.
          # A commit is a version bump IFF it touches third_party/prebuilt/repo
          DONT_PICK=$(cat <<EOF
          35e1556f6f329714a9d730ea4a7743317535ce1a
          2ed353a57eb379a3b8fa6401cbf3a7abe3da7e8b
          d961b62f71147bfd148d8648bfdf566525a401e7
          fbb02bfeafdb69b876bc6c0bd433fd1ebf4c8150
          EOF
          )
          git config --global user.email "kotlin-symbol-processing@google.com"
          git config --global user.name "KSP Auto Pick"
          MERGE_BASE=$(git merge-base HEAD origin/main)
          CANDIDATES=$(git log --pretty=%H $MERGE_BASE..origin/main)
          PICKED=$(git log $MERGE_BASE..HEAD | sed -n "s/^[ ]*(cherry picked from commit \([a-z0-9]*\))$/\1/p")
          VERSION_BUMPS=$(git log $MERGE_BASE..origin/main --pretty=%H --grep UPDATE_KOTLIN_VERSION)
          AA_COMMITS=$(git log $MERGE_BASE..origin/main --pretty=%H kotlin-analysis-api)
          TO_PICK=$(grep -Fxv -f <(echo "$PICKED"; echo "$VERSION_BUMPS"; echo "$DONT_PICK"; echo "$AA_COMMITS") <(echo "$CANDIDATES") | tac)
          echo Picking $TO_PICK
          if [ -n "$TO_PICK" ]; then git cherry-pick -x $TO_PICK; fi

      - name: push to release branch
        run: git push origin