|
| 1 | +name: 'esmeta yet phrases detection' |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize] |
| 6 | + |
| 7 | +jobs: |
| 8 | + esmeta-new-phrases: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + |
| 11 | + env: |
| 12 | + ESMETA_HOME: vendor/esmeta |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + - name: Setup JDK |
| 20 | + uses: actions/setup-java@v4 |
| 21 | + with: |
| 22 | + distribution: temurin |
| 23 | + java-version: 17 |
| 24 | + - name: Setup SBT |
| 25 | + uses: sbt/setup-sbt@v1 |
| 26 | + - name: download esmeta |
| 27 | + run: | |
| 28 | + mkdir -p "${ESMETA_HOME}" |
| 29 | + cd "${ESMETA_HOME}" |
| 30 | + git init |
| 31 | + git remote add origin https://github.com/es-meta/esmeta.git |
| 32 | + git fetch --depth 1 origin bd58590ef6badabbe71afdefa02dc32274902621 ;# v0.7.1 |
| 33 | + git checkout FETCH_HEAD |
| 34 | + - name: build esmeta |
| 35 | + run: | |
| 36 | + cd "${ESMETA_HOME}" |
| 37 | + sbt assembly |
| 38 | + - name: link |
| 39 | + run: | |
| 40 | + rmdir "${ESMETA_HOME}"/ecma262 \ |
| 41 | + && ln -s "$(pwd)" "${ESMETA_HOME}"/ecma262 |
| 42 | +
|
| 43 | + - id: collect |
| 44 | + name: List added line numbers |
| 45 | + shell: bash |
| 46 | + env: |
| 47 | + FILE_PATH: spec.html |
| 48 | + BASE_SHA: ${{ github.event.pull_request.base.sha }} |
| 49 | + HEAD_SHA: ${{ github.sha }} |
| 50 | + run: | |
| 51 | + # zero-context diff, limited to the file we care about |
| 52 | + added_lines=$(git diff -U0 --no-color "${BASE_SHA}" "${HEAD_SHA}" -- "${FILE_PATH}" | |
| 53 | + # keep only the hunk headers (the @@ lines) |
| 54 | + awk ' |
| 55 | + # Example header: @@ -158,0 +159,2 @@ |
| 56 | + /^@@/ { |
| 57 | + # Extract “+<start>[,<count>]” part |
| 58 | + match($0, /\+([0-9]+)(,([0-9]+))?/, a) |
| 59 | + start = a[1] |
| 60 | + count = (a[3] == "" ? 1 : a[3]) |
| 61 | + # Print every line number in the added range |
| 62 | + for (i = 0; i < count; i++) print start + i |
| 63 | + } |
| 64 | + ') |
| 65 | +
|
| 66 | + # Join line numbers with comma or space (whichever format you need) |
| 67 | + added_joined=$(echo "$added_lines" | paste -sd "," -) |
| 68 | + added_lines_json="[$added_joined]" |
| 69 | +
|
| 70 | + # Set it as an output value |
| 71 | + echo "added_lines=$added_lines_json" >> "$GITHUB_OUTPUT" |
| 72 | +
|
| 73 | + - name: check newly introduces phrases |
| 74 | + run: | |
| 75 | + "${ESMETA_HOME}"/bin/esmeta extract \ |
| 76 | + -status \ |
| 77 | + -extract:warn-action <<< ${{ steps.collect.outputs.added_lines }} |
0 commit comments