|
| 1 | +name: Check and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "*/30 * * * *" # runs every 30 minutes |
| 6 | + |
| 7 | +jobs: |
| 8 | + check_deploy: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + # 1. Checkout the repository. |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v3 |
| 14 | + |
| 15 | + # 2. Setup Node.js environment. |
| 16 | + - name: Setup Node.js |
| 17 | + uses: actions/setup-node@v3 |
| 18 | + with: |
| 19 | + node-version: "16" |
| 20 | + |
| 21 | + # 3. (Optional) Install additional dependencies for Puppeteer. |
| 22 | + - name: Install Puppeteer dependencies |
| 23 | + run: | |
| 24 | + sudo apt-get update |
| 25 | + sudo apt-get install -y libnss3 libatk-bridge2.0-0 libx11-xcb1 libxcomposite1 libxrandr2 libasound2 |
| 26 | +
|
| 27 | + # 4. Use Puppeteer to check if the website shows the update text. |
| 28 | + - name: Check website for update text with Puppeteer |
| 29 | + id: check |
| 30 | + run: | |
| 31 | + npm install puppeteer |
| 32 | + node -e "const puppeteer = require('puppeteer'); (async () => { |
| 33 | + const browser = await puppeteer.launch({ args: ['--no-sandbox'] }); |
| 34 | + const page = await browser.newPage(); |
| 35 | + await page.goto('https://www.validityops.com', { waitUntil: 'networkidle2' }); |
| 36 | + const text = await page.evaluate(() => document.body.innerText); |
| 37 | + const found = text.includes('Your Namadillo version is not compatible with the current Namada Indexer'); |
| 38 | + console.log('Found text:', found); |
| 39 | + const fs = require('fs'); |
| 40 | + fs.appendFileSync(process.env.GITHUB_OUTPUT, 'found=' + (found ? 'true' : 'false') + '\n'); |
| 41 | + await browser.close(); |
| 42 | + })();" |
| 43 | +
|
| 44 | + # 5. If the text is found, add upstream remote and merge its main branch. |
| 45 | + - name: Merge upstream changes if update text found |
| 46 | + if: steps.check.outputs.found == 'true' |
| 47 | + run: | |
| 48 | + git remote add upstream https://github.com/anoma/namada-interface.git || true |
| 49 | + git fetch upstream |
| 50 | + git checkout main |
| 51 | + git merge upstream/main --no-edit |
| 52 | +
|
| 53 | + # 6. Build the Namadillo app. |
| 54 | + - name: Build Namadillo app |
| 55 | + if: steps.check.outputs.found == 'true' |
| 56 | + run: | |
| 57 | + cd apps/namadillo |
| 58 | + yarn install |
| 59 | + yarn build |
| 60 | +
|
| 61 | + # 7. Add the rewrites file in the build output (dist). |
| 62 | + - name: Add rewrites file |
| 63 | + if: steps.check.outputs.found == 'true' |
| 64 | + run: | |
| 65 | + cd apps/namadillo/dist |
| 66 | + echo '{ "rewrites": [ { "source": "/(.*)", "destination": "/index.html" } ] }' > rewrites.json |
| 67 | +
|
| 68 | + # 8. Commit and push changes back to main. |
| 69 | + - name: Commit and push changes |
| 70 | + if: steps.check.outputs.found == 'true' |
| 71 | + run: | |
| 72 | + git config user.name "github-actions[bot]" |
| 73 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 74 | + git add . |
| 75 | + git commit -m "Auto-update: merge upstream changes and add rewrites" || echo "No changes to commit" |
| 76 | + git push origin main |
| 77 | +
|
| 78 | + # 9. Deploy using Vercel by piping in the required responses. |
| 79 | + - name: Deploy with Vercel |
| 80 | + if: steps.check.outputs.found == 'true' |
| 81 | + run: | |
| 82 | + npm install -g vercel |
| 83 | + # The following simulates: |
| 84 | + # 1) "y" + Enter |
| 85 | + # 2) Enter |
| 86 | + # 3) "y" + Enter |
| 87 | + # 4) "namada" + Enter |
| 88 | + printf "y\n\ny\nnamada\n" | vercel --prod |
0 commit comments