summaryrefslogtreecommitdiff
path: root/.forgejo/workflows/kernel-update-check.yml
blob: 5e7e16d6c881956e9831d6f09c50aea6f061626e (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
156
157
158
159
160
161
162
163
164
165
name: Kernel Update Check

on:
  schedule:
    - cron: '0 6 1,15 * *'
  workflow_dispatch:

concurrency:
  group: kernel-update-check
  cancel-in-progress: false

jobs:
  check-update:
    runs-on: iso-builder

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.FORGEJO_TOKEN }}

      - name: Check CachyOS kernel version
        id: check
        run: |
          set -euo pipefail
          PKGBUILD=$(curl -fsSL --retry 3 \
            "https://raw.githubusercontent.com/CachyOS/linux-cachyos/master/linux-cachyos/PKGBUILD")
          MAJOR=$(echo "$PKGBUILD" | grep '^_major=' | cut -d= -f2)
          MINOR=$(echo "$PKGBUILD" | grep '^_minor=' | cut -d= -f2)
          TAGREL=$(echo "$PKGBUILD" | grep '^_tagrel=' | cut -d= -f2)
          if [ -z "$MAJOR" ] || [ -z "$MINOR" ] || [ -z "$TAGREL" ]; then
            echo "HIBA: Nem sikerult a CachyOS verziot lekerdezni"
            exit 1
          fi
          for v in "$MAJOR" "$MINOR" "$TAGREL"; do
            case "$v" in
              *[!0-9]*) echo "HIBA: Ervenytelen verzio: $v"; exit 1 ;;
            esac
          done
          echo "MAJOR=$MAJOR" >> $GITHUB_OUTPUT
          echo "MINOR=$MINOR" >> $GITHUB_OUTPUT
          echo "TAGREL=$TAGREL" >> $GITHUB_OUTPUT
          echo "Legfrissebb CachyOS: ${MAJOR}.${MINOR}-${TAGREL}"

      - name: Read current version
        id: current
        run: |
          set -euo pipefail
          MAJOR=$(grep '^_major=' linux-raveos/PKGBUILD | cut -d= -f2)
          MINOR=$(grep '^_minor=' linux-raveos/PKGBUILD | cut -d= -f2)
          TAGREL=$(grep '^_tagrel=' linux-raveos/PKGBUILD | cut -d= -f2)
          PKGVER=$(grep '^pkgver=' linux-raveos/PKGBUILD | cut -d= -f2)
          echo "MAJOR=$MAJOR" >> $GITHUB_OUTPUT
          echo "MINOR=$MINOR" >> $GITHUB_OUTPUT
          echo "TAGREL=$TAGREL" >> $GITHUB_OUTPUT
          echo "PKGVER=$PKGVER" >> $GITHUB_OUTPUT
          echo "Jelenlegi: ${MAJOR}.${MINOR}-${TAGREL} (pkgver=${PKGVER})"

      - name: Frissites szukseges?
        id: needsupdate
        env:
          NEW_MAJOR: ${{ steps.check.outputs.MAJOR }}
          NEW_MINOR: ${{ steps.check.outputs.MINOR }}
          NEW_TAGREL: ${{ steps.check.outputs.TAGREL }}
          CUR_MAJOR: ${{ steps.current.outputs.MAJOR }}
          CUR_MINOR: ${{ steps.current.outputs.MINOR }}
          CUR_TAGREL: ${{ steps.current.outputs.TAGREL }}
        run: |
          set -euo pipefail
          NEW="${NEW_MAJOR}.${NEW_MINOR}-${NEW_TAGREL}"
          CUR="${CUR_MAJOR}.${CUR_MINOR}-${CUR_TAGREL}"
          if [ "$NEW" != "$CUR" ]; then
            echo "UPDATE=yes" >> $GITHUB_OUTPUT
            echo "Frissites: $CUR -> $NEW"
          else
            echo "UPDATE=no" >> $GITHUB_OUTPUT
            echo "Aktualis, nincs frissites: $CUR"
          fi

      - name: PR mar letezik?
        id: prcheck
        if: steps.needsupdate.outputs.UPDATE == 'yes'
        env:
          NEW_MAJOR: ${{ steps.check.outputs.MAJOR }}
          NEW_MINOR: ${{ steps.check.outputs.MINOR }}
          NEW_TAGREL: ${{ steps.check.outputs.TAGREL }}
        run: |
          set -euo pipefail
          BRANCH="update/kernel-${NEW_MAJOR}.${NEW_MINOR}-${NEW_TAGREL}"
          OPEN_PRS=$(curl -fsSL \
            -H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
            "https://git.rp1.hu/api/v1/repos/${{ github.repository }}/pulls?state=open&limit=50")
          EXISTS=$(echo "$OPEN_PRS" | python3 -c "
          import sys, json
          pulls = json.load(sys.stdin)
          branch = '$BRANCH'
          found = any(p.get('head', {}).get('ref', '') == branch for p in pulls)
          print('yes' if found else 'no')
          ")
          echo "EXISTS=$EXISTS" >> $GITHUB_OUTPUT
          echo "PR letezik: $EXISTS"

      - name: PKGBUILD frissitese es PR nyitasa
        if: steps.needsupdate.outputs.UPDATE == 'yes' && steps.prcheck.outputs.EXISTS == 'no'
        env:
          NEW_MAJOR: ${{ steps.check.outputs.MAJOR }}
          NEW_MINOR: ${{ steps.check.outputs.MINOR }}
          NEW_TAGREL: ${{ steps.check.outputs.TAGREL }}
          OLD_PKGVER: ${{ steps.current.outputs.PKGVER }}
          OLD_MAJOR: ${{ steps.current.outputs.MAJOR }}
          OLD_MINOR: ${{ steps.current.outputs.MINOR }}
          OLD_TAGREL: ${{ steps.current.outputs.TAGREL }}
        run: |
          set -euo pipefail

          CUR="${OLD_MAJOR}.${OLD_MINOR}-${OLD_TAGREL}"
          NEW_PKGVER="${NEW_MAJOR}.${NEW_MINOR}"

          OLD_PKGREL=$(grep '^pkgrel=' linux-raveos/PKGBUILD | cut -d= -f2)

          if [ "${OLD_MAJOR}.${OLD_MINOR}" != "${NEW_MAJOR}.${NEW_MINOR}" ]; then
            NEW_PKGREL=10
          elif [ "$OLD_PKGREL" -lt 10 ]; then
            NEW_PKGREL=10
          else
            NEW_PKGREL=$((OLD_PKGREL + 1))
          fi

          BRANCH="update/kernel-${NEW_MAJOR}.${NEW_MINOR}-${NEW_TAGREL}"

          git config user.name "RaveOS Bot"
          git config user.email "bot@raveos.hu"
          git checkout -b "$BRANCH"

          sed -i "s/^_major=.*/_major=${NEW_MAJOR}/" linux-raveos/PKGBUILD
          sed -i "s/^_minor=.*/_minor=${NEW_MINOR}/" linux-raveos/PKGBUILD
          sed -i "s/^_tagrel=.*/_tagrel=${NEW_TAGREL}/" linux-raveos/PKGBUILD
          sed -i "s/^pkgver=.*/pkgver=${NEW_PKGVER}/" linux-raveos/PKGBUILD
          sed -i "s/^pkgrel=.*/pkgrel=${NEW_PKGREL}/" linux-raveos/PKGBUILD

          curl -fsSL --retry 3 \
            "https://raw.githubusercontent.com/CachyOS/linux-cachyos/master/linux-cachyos/config" \
            -o linux-raveos/config
          sed -i 's/^CONFIG_ZRAM=m$/CONFIG_ZRAM=y/' linux-raveos/config
          sed -i 's/^# CONFIG_ZRAM is not set$/CONFIG_ZRAM=y/' linux-raveos/config
          sed -i 's/^CONFIG_NTSYNC=m$/CONFIG_NTSYNC=y/' linux-raveos/config
          sed -i 's/^# CONFIG_NTSYNC is not set$/CONFIG_NTSYNC=y/' linux-raveos/config

          git add linux-raveos/PKGBUILD linux-raveos/config
          git commit -m "update: linux-cachyos ${NEW_MAJOR}.${NEW_MINOR}-${NEW_TAGREL} (pkgver=${NEW_PKGVER}-${NEW_PKGREL})"

          git push origin "$BRANCH"

          curl -fsSL -X POST \
            -H "Authorization: token ${{ secrets.FORGEJO_TOKEN }}" \
            -H "Content-Type: application/json" \
            "https://git.rp1.hu/api/v1/repos/${{ github.repository }}/pulls" \
            -d "{
              \"title\": \"kernel update: ${CUR} -> ${NEW_MAJOR}.${NEW_MINOR}-${NEW_TAGREL}\",
              \"head\": \"${BRANCH}\",
              \"base\": \"main\",
              \"body\": \"Automatikus kernel verzio frissites.\n\n- Regi: \`${CUR}\` (pkgver=${OLD_PKGVER})\n- Uj: \`${NEW_MAJOR}.${NEW_MINOR}-${NEW_TAGREL}\` (pkgver=${NEW_PKGVER})\n\nMerge utan automatikusan elindul a build.\"
            }"
          echo "PR megnyitva: $BRANCH -> main"