Welcome to mirror list, hosted at ThFree Co, Russian Federation.

buildvue.yml « workflows « .github - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5c6a1ae9d8caecd1983a9e7407519ca51cbbd7ed (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: Build Vue files

on:
  pull_request:
    types: [synchronize, opened]

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-latest
    steps:
      - name: Detect branch for PR
        id: vars
        run: |
          PR="${{ github.event.pull_request.number }}"

          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)
          BASE_SHA=$(echo "${PR_INFO}" | jq -r .base.sha)

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

          echo ::set-output name=islocalbranch::$BASE == $GITHUB_REPOSITORY
          echo ::set-output name=branch::$REF
          echo ::set-output name=base::$BASE_SHA
      - uses: actions/checkout@v2
        with:
          lfs: false
        if: steps.vars.outputs.branch != ''
      - name: Check vue changes
        id: vuecheck
        run: |
          git fetch --depth=1 origin ${{ steps.vars.outputs.base }}

          VUE_FILES_MODIFIED=$(git diff --name-only ${{ steps.vars.outputs.base }} -- plugins/*/vue/**/* | wc -l)

          if [[ $VUE_FILES_MODIFIED == "0" ]]
          then
            echo "No vue files modified"
            exit 0;
          fi

          echo ::set-output name=vue_modified::1
        if: steps.vars.outputs.branch != ''
      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.0'
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - name: Setup node
        uses: actions/setup-node@v2
        with:
          node-version: '16'
          cache: 'npm'
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - run: npm install
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - name: Get composer cache directory
        id: composer-cache
        run: echo "::set-output name=dir::$(composer config cache-files-dir)"
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - name: Cache dependencies
        uses: actions/cache@v2
        with:
          path: ${{ steps.composer-cache.outputs.dir }}
          key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
          restore-keys: ${{ runner.os }}-composer-
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - name: Install dependencies
        run: composer install --prefer-dist
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - name: Quick Matomo Install
        run: |
          cat <<-EOF > ./config/config.ini.php
          [General]
          always_load_commands_from_plugin=CoreVue

          [Development]
          enabled = 1
          EOF

          cat ./config/config.ini.php
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - 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"
          if [[ ${{ steps.vars.outputs.islocalbranch }} ]]
          then
            git checkout ${{ steps.vars.outputs.branch }}
          fi
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - name: Build Vue Modules
        run: php ./console vue:build
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - name: Push changes
        id: push
        run: |
          if [[ $( git diff --numstat plugins/*/vue/dist/*.js ) ]]
          then
            if [[ ! ${{ steps.vars.outputs.islocalbranch }} ]]
            then
              echo "It's only possible to update local branches automatically. Adding a comment instead."
              echo ::set-output name=failure::1
            else
              cd $GITHUB_WORKSPACE
              git add plugins/*/vue/dist/*.js plugins/*/vue/dist/*.json
              git commit -m "built vue files"
              git push
            fi
          fi
        if: steps.vars.outputs.branch != '' && steps.vuecheck.outputs.vue_modified == '1'
      - uses: actions/github-script@v5
        with:
          script: |
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: 'Vue files are not up to date. Please build the files using `./console vue:build` locally and push them to your branch.'
            })
        if: steps.push.outputs.failure == '1'
      - name: Fail if not up to date
        run: exit 1
        if: steps.push.outputs.failure == '1'