aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/update-pkgbuilds.yml
blob: 273629c21fec0968fe18c29d6058c89df5084057 (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
name: Update PKGBUILDs

on:
  schedule:
    - cron: '0 4 * * *'
  workflow_dispatch:

jobs:
  update-sing-box-beta-bin:
    name: Update sing-box-beta-bin
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v6

      - name: Get latest pre-release version
        id: version
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          VERSION=$(gh api repos/SagerNet/sing-box/releases \
            --jq '[.[] | select(.prerelease)] | first | .tag_name | ltrimstr("v")')
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"

      - name: Check current version
        id: check
        run: |
          CURRENT=$(grep '^_pkgver=' repo/sing-box-beta-bin/PKGBUILD | cut -d'"' -f2)
          echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
          if [ "$CURRENT" = "${{ steps.version.outputs.version }}" ]; then
            echo "skip=true" >> "$GITHUB_OUTPUT"
          else
            echo "skip=false" >> "$GITHUB_OUTPUT"
          fi

      - name: Download assets and compute sha256sums
        if: steps.check.outputs.skip == 'false'
        id: sums
        env:
          VERSION: ${{ steps.version.outputs.version }}
          GIT_URL: https://github.com/SagerNet/sing-box
        run: |
          for ARCH in x86_64 aarch64 armv7h; do
            # upstream uses armv7hl in filenames for armv7h
            FILE_ARCH="$ARCH"
            [ "$ARCH" = "armv7h" ] && FILE_ARCH="armv7hl"
            FILE="sing-box_${VERSION}_linux_${FILE_ARCH}.pkg.tar.zst"
            URL="$GIT_URL/releases/download/v${VERSION}/$FILE"
            wget -q "$URL" -O "$FILE"
            SUM=$(sha256sum "$FILE" | awk '{print $1}')
            echo "sum_${ARCH}=$SUM" >> "$GITHUB_OUTPUT"
            rm "$FILE"
          done

      - name: Update PKGBUILD
        if: steps.check.outputs.skip == 'false'
        env:
          VERSION: ${{ steps.version.outputs.version }}
          SUM_X86_64: ${{ steps.sums.outputs.sum_x86_64 }}
          SUM_ARMV7H: ${{ steps.sums.outputs.sum_armv7h }}
          SUM_AARCH64: ${{ steps.sums.outputs.sum_aarch64 }}
        run: |
          sed -i "s/^_pkgver=.*/_pkgver=\"${VERSION}\"/" repo/sing-box-beta-bin/PKGBUILD
          sed -i "s/^pkgrel=.*/pkgrel=\"1\"/" repo/sing-box-beta-bin/PKGBUILD
          sed -i "s/^sha256sums_x86_64=.*/sha256sums_x86_64=(\"${SUM_X86_64}\")/" repo/sing-box-beta-bin/PKGBUILD
          sed -i "s/^sha256sums_armv7h=.*/sha256sums_armv7h=(\"${SUM_ARMV7H}\")/" repo/sing-box-beta-bin/PKGBUILD
          sed -i "s/^sha256sums_aarch64=.*/sha256sums_aarch64=(\"${SUM_AARCH64}\")/" repo/sing-box-beta-bin/PKGBUILD

      - name: Commit and push
        if: steps.check.outputs.skip == 'false'
        env:
          VERSION: ${{ steps.version.outputs.version }}
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add repo/sing-box-beta-bin/PKGBUILD
          git commit -m "feat(pkg): Update sing-box-beta-bin to ${VERSION}"
          git push

  update-telegram-bot-api:
    name: Update telegram-bot-api
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v6

      - name: Get latest version from CMakeLists.txt
        id: version
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          VERSION=$(curl -sf "https://raw.githubusercontent.com/tdlib/telegram-bot-api/master/CMakeLists.txt" \
            | grep -oP 'project\(TelegramBotApi VERSION \K[0-9]+\.[0-9]+')
          COMMIT=$(gh api repos/tdlib/telegram-bot-api/commits/master --jq '.sha')
          echo "version=$VERSION" >> "$GITHUB_OUTPUT"
          echo "commit=$COMMIT" >> "$GITHUB_OUTPUT"

      - name: Check current version
        id: check
        run: |
          CURRENT=$(grep '^pkgver=' repo/telegram-bot-api/PKGBUILD | cut -d'=' -f2)
          echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
          if [ "$CURRENT" = "${{ steps.version.outputs.version }}" ]; then
            echo "skip=true" >> "$GITHUB_OUTPUT"
          else
            echo "skip=false" >> "$GITHUB_OUTPUT"
          fi

      - name: Update PKGBUILD
        if: steps.check.outputs.skip == 'false'
        env:
          VERSION: ${{ steps.version.outputs.version }}
          COMMIT: ${{ steps.version.outputs.commit }}
        run: |
          sed -i "s/^pkgver=.*/pkgver=${VERSION}/" repo/telegram-bot-api/PKGBUILD
          sed -i "s/^pkgrel=.*/pkgrel=1/" repo/telegram-bot-api/PKGBUILD
          sed -i "s/#commit=[0-9a-f]*/#commit=${COMMIT}/" repo/telegram-bot-api/PKGBUILD

      - name: Commit and push
        if: steps.check.outputs.skip == 'false'
        env:
          VERSION: ${{ steps.version.outputs.version }}
        run: |
          git config user.name "github-actions[bot]"
          git config user.email "github-actions[bot]@users.noreply.github.com"
          git add repo/telegram-bot-api/PKGBUILD
          git commit -m "feat(pkg): Update telegram-bot-api to ${VERSION}"
          git push