|
| 1 | +name: Mirrors |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - 'mirrors/**' |
| 9 | + - 'wiki/mirrors_header.md' |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - 'mirrors/**' |
| 13 | + |
| 14 | +jobs: |
| 15 | + lint-mirror-files: |
| 16 | + runs-on: ubuntu-slim |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Check out repository |
| 20 | + uses: actions/checkout@v6 |
| 21 | + |
| 22 | + - name: Check mirror files |
| 23 | + run: | |
| 24 | + for file in mirrors/default $(git ls-files mirrors/*/*); do |
| 25 | + if head -n 4 "$file" | grep -qv '^#'; then |
| 26 | + echo "Error: $file does not have 4 header lines starting with #" > /dev/stderr |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +
|
| 30 | + if ! grep -q '^MAIN=' "$file"; then |
| 31 | + echo "Error: $file does not contain MAIN" > /dev/stderr |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + if ! grep -q '^ROOT=' "$file"; then |
| 35 | + echo "Error: $file does not contain ROOT" > /dev/stderr |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + if ! grep -q '^X11=' "$file"; then |
| 39 | + echo "Error: $file does not contain X11" > /dev/stderr |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +
|
| 43 | + if ! grep -q "$(basename $file)" mirrors/Makefile.am; then |
| 44 | + echo "Error: $file is not listed in mirrors/Makefile.am" |
| 45 | + fi |
| 46 | +
|
| 47 | + echo "$file passed validation." |
| 48 | + done |
| 49 | +
|
| 50 | + update-wiki-mirror: |
| 51 | + runs-on: ubuntu-slim |
| 52 | + needs: lint-mirror-files |
| 53 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 54 | + |
| 55 | + steps: |
| 56 | + - name: Check out repository |
| 57 | + uses: actions/checkout@v6 |
| 58 | + |
| 59 | + - name: Set up SSH key |
| 60 | + env: |
| 61 | + GITHUB_SSH_KEY: ${{ secrets.TERMUXBOT2_SSH_KEY }} |
| 62 | + run: | |
| 63 | + mkdir -p ~/.ssh |
| 64 | + echo "$GITHUB_SSH_KEY" > ~/.ssh/id_ed25519_termuxbot2 |
| 65 | + chmod 600 ~/.ssh/id_ed25519_termuxbot2 |
| 66 | + ssh-keyscan github.com >> ~/.ssh/known_hosts |
| 67 | +
|
| 68 | + - name: Clone termux-packages.wiki |
| 69 | + run: | |
| 70 | + if [ ! -d termux-packages.wiki ]; then |
| 71 | + GIT_SSH_COMMAND="ssh -i ~/.ssh/id_ed25519_termuxbot2" git clone git@github.com:termux/termux-packages.wiki.git |
| 72 | + cd termux-packages.wiki |
| 73 | + else |
| 74 | + cd termux-packages.wiki |
| 75 | + git pull origin master |
| 76 | + fi |
| 77 | + git config --global user.name "Termux Github Actions" |
| 78 | + git config --global user.email "contact@termux.dev" |
| 79 | +
|
| 80 | + - name: Generate the Wiki page |
| 81 | + run: | |
| 82 | + cd termux-packages.wiki |
| 83 | + bash ../mirrors/generate-wiki-page.sh |
| 84 | +
|
| 85 | + - name: Commit and push changes |
| 86 | + run: | |
| 87 | + cd termux-packages.wiki |
| 88 | + git add Mirrors.md |
| 89 | + # Check if there are any changes before commiting and pushing |
| 90 | + if ! git diff --cached --exit-code > /dev/null; then |
| 91 | + git commit -m "Update Mirrors.md after termux-tools commit ${GITHUB_SHA::12}" \ |
| 92 | + -m "See https://github.com/termux/termux-tools/tree/${GITHUB_SHA}." |
| 93 | + GIT_SSH_COMMAND="ssh -i ~/.ssh/id_ed25519_termuxbot2" git push origin master |
| 94 | + fi |
0 commit comments