summaryrefslogtreecommitdiff
path: root/.forgejo/workflows/hyprland-update-check.yml
blob: f6afab7606c7ed10d76e47b57b96db8a7766e82e (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
name: Hyprland Stack Update Check

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

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

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

      - name: Check for existing open PR
        id: prcheck
        run: |
          set -euo pipefail
          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)
          found = any(p.get('head', {}).get('ref', '').startswith('update/hyprland-stack') for p in pulls)
          print('yes' if found else 'no')
          ")
          echo "EXISTS=$EXISTS" >> $GITHUB_OUTPUT
          echo "Open PR exists: $EXISTS"

      - name: Check upstream versions
        id: check
        if: steps.prcheck.outputs.EXISTS == 'no'
        run: |
          set -euo pipefail
          sudo pacman -S --needed --noconfirm pacman-contrib curl jq

          UPDATED_PKGS=()
          SUMMARY=""

          PKGS=(
            hyprutils
            hyprlang
            hyprwayland-scanner
            aquamarine
            hyprcursor
            hyprgraphics
            hyprwire
            hyprland-guiutils
            hyprland
            xdg-desktop-portal-hyprland
            hyprpolkitagent
            hyprland-qt-support
            dms-shell
          )

          for pkg in "${PKGS[@]}"; do
            dir="hyprland-raveos/$pkg"
            [ -d "$dir" ] || continue

            LOCAL_VER=$(grep '^pkgver=' "$dir/PKGBUILD" | head -1 | cut -d= -f2 | tr -d "'\"")
            
            UPSTREAM_PKGBUILD=$(curl -fsSL --retry 3 "https://gitlab.archlinux.org/archlinux/packaging/packages/${pkg}/-/raw/main/PKGBUILD" 2>/dev/null || true)
            [ -n "$UPSTREAM_PKGBUILD" ] || continue

            UPSTREAM_VER=$(echo "$UPSTREAM_PKGBUILD" | grep '^pkgver=' | head -1 | cut -d= -f2 | tr -d "'\"")
            [ -n "$UPSTREAM_VER" ] || continue

            if [ "$LOCAL_VER" != "$UPSTREAM_VER" ]; then
              echo "Update available for $pkg: $LOCAL_VER -> $UPSTREAM_VER"
              
              # Frissites letoltese es pkgrel beallitasa
              echo "$UPSTREAM_PKGBUILD" > "$dir/PKGBUILD"
              sed -i 's/^pkgrel=[0-9]*/pkgrel=10/' "$dir/PKGBUILD"
              if [ "$pkg" = "hyprpolkitagent" ] || [ "$pkg" = "hyprland-qt-support" ]; then
                sed -i 's/^pkgrel=10/pkgrel=20/' "$dir/PKGBUILD"
              fi

              UPDATED_PKGS+=("$pkg")
              SUMMARY="${SUMMARY}\n- **${pkg}**: \`${LOCAL_VER}\` -> \`${UPSTREAM_VER}-10\`"
            else
              echo "$pkg is up-to-date ($LOCAL_VER)"
            fi
          done

          if [ ${#UPDATED_PKGS[@]} -gt 0 ]; then
            echo "HAS_UPDATES=yes" >> $GITHUB_OUTPUT
            echo "COUNT=${#UPDATED_PKGS[@]}" >> $GITHUB_OUTPUT
            echo -e "SUMMARY<<EOF\n${SUMMARY}\nEOF" >> $GITHUB_OUTPUT
          else
            echo "HAS_UPDATES=no" >> $GITHUB_OUTPUT
            echo "No updates found for hyprland stack."
          fi

      - name: Create branch and open single Pull Request
        if: steps.prcheck.outputs.EXISTS == 'no' && steps.check.outputs.HAS_UPDATES == 'yes'
        run: |
          set -euo pipefail
          DATE=$(date +%Y%m%d-%H%M)
          BRANCH="update/hyprland-stack-${DATE}"

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

          git add hyprland-raveos/
          git commit -m "update: hyprland stack (${{ steps.check.outputs.COUNT }} packages)"

          git remote set-url origin "https://bot:${{ secrets.FORGEJO_TOKEN }}@git.rp1.hu/RaveOS/RaveOS-PKGBUILD.git"
          git push origin "$BRANCH"

          PR_BODY="Automata Hyprland stack frissítés (${{ steps.check.outputs.COUNT }} csomag):\n${{ steps.check.outputs.SUMMARY }}\n\nA csomagok a merge után az \`iso-builder\` runneren sorrendben fordulnak le, GPG aláírással kerülnek a RaveOS repóba."

          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 "$(jq -n \
              --arg title "Hyprland stack frissítés (${{ steps.check.outputs.COUNT }} csomag)" \
              --arg head "$BRANCH" \
              --arg base "main" \
              --arg body "$PR_BODY" \
              '{title: $title, head: $head, base: $base, body: $body}')"

          echo "Single PR successfully opened for hyprland stack update."