File: buildtrackerjs.yml

package info (click to toggle)
matomo 5.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 95,068 kB
  • sloc: php: 289,425; xml: 127,249; javascript: 112,130; python: 202; sh: 178; makefile: 20; sql: 10
file content (98 lines) | stat: -rw-r--r-- 3,239 bytes parent folder | download
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
name: Build Tracker JS files

on:
  issue_comment:
    types: [created]

permissions:
  actions: read
  checks: none
  contents: write
  deployments: none
  issues: read
  packages: none
  pull-requests: write
  repository-projects: none
  security-events: none
  statuses: none

jobs:
  build:
    runs-on: ubuntu-24.04

    steps:
    - name: Detect branch for PR
      id: vars
      run: |
        PR=$( echo "${{ github.event.comment.issue_url }}" | grep -oE 'issues/([0-9]+)$' | cut -d'/' -f 2 )

        PR_INFO=$( curl \
                 --request GET \
                 --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
                 --header 'content-type: application/json' \
                 --url https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/$PR )
        REF=$(echo "${PR_INFO}" | jq -r .head.ref)
        BASE=$(echo "${PR_INFO}" | jq -r .head.repo.full_name)
        STATE=$(echo "${PR_INFO}" | jq -r .state)

        if [[ $STATE == "closed" ]]
        then
          echo "Pull Request already closed."
          exit 0;
        fi

        if [[ $BASE != $GITHUB_REPOSITORY ]]
        then
          echo "It's only possible to update local branches"
          exit 0;
        fi

        echo "branch=$REF" >> $GITHUB_OUTPUT
      if: github.event.comment.body == 'build js'
    - uses: actions/setup-java@v5
      with:
        distribution: 'zulu'
        java-version: '9'
      if: steps.vars.outputs.branch != ''
    - uses: actions/checkout@v6
      with:
        ref: ${{ steps.vars.outputs.branch }}
        lfs: false
        persist-credentials: false
      if: steps.vars.outputs.branch != ''
    - name: Prepare git config
      run: |
          cat <<- EOF > $HOME/.netrc
            machine github.com
            login $GITHUB_ACTOR
            password $GITHUB_TOKEN
            machine api.github.com
            login $GITHUB_ACTOR
            password $GITHUB_TOKEN
          EOF
          chmod 600 $HOME/.netrc
          git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
          git config --global user.name "$GITHUB_ACTOR"
          git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
      if: steps.vars.outputs.branch != ''
    - name: Fetch YUICompressor
      run: |
        cd $GITHUB_WORKSPACE/js
        wget https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.zip
        unzip yuicompressor-2.4.8.zip
      if: steps.vars.outputs.branch != ''
    - name: Build JS files
      run: |
        cd $GITHUB_WORKSPACE/js
        sed '/<DEBUG>/,/<\/DEBUG>/d' < piwik.js | sed 's/eval/replacedEvilString/' | java -jar yuicompressor-2.4.8.jar --type js --line-break 1000 | sed 's/replacedEvilString/eval/' | sed 's/^[/][*]/\/*!/' > piwik.min.js && cp piwik.min.js ../piwik.js && cp piwik.min.js ../matomo.js
      if: steps.vars.outputs.branch != ''
    - name: Push changes
      run: |
          if [[ $( git diff --numstat ) ]]
          then
            cd $GITHUB_WORKSPACE
            git add piwik.js matomo.js js/piwik.min.js
            git commit -m "Build tracker JS files"
            git push
          fi
      if: steps.vars.outputs.branch != ''