|
| 1 | +name: Sync from Xano |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + fromBranchName: |
| 7 | + description: 'From branch name' |
| 8 | + required: false |
| 9 | + default: 'dev' |
| 10 | + toBranchName: |
| 11 | + description: 'To branch' |
| 12 | + required: true |
| 13 | + default: 'prod' |
| 14 | + toBranchUrl: |
| 15 | + description: "GCP Signed URL for the 'to' branch" |
| 16 | + required: true |
| 17 | + actionType: |
| 18 | + description: "What is the action that happened, available options: 'merge', 'new'" |
| 19 | + required: true |
| 20 | + default: 'merge' |
| 21 | + type: choice |
| 22 | + options: |
| 23 | + - merge |
| 24 | + - new |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: write |
| 28 | + pull-requests: write |
| 29 | + |
| 30 | +jobs: |
| 31 | + merge: |
| 32 | + if: ${{ github.event.inputs.actionType == 'merge' }} |
| 33 | + runs-on: ubuntu-latest |
| 34 | + |
| 35 | + steps: |
| 36 | + - name: Checkout repository |
| 37 | + uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - name: Set up Node.js |
| 40 | + |
| 41 | + with: |
| 42 | + node-version: 'latest' |
| 43 | + |
| 44 | + - name: Install dependencies |
| 45 | + run: npm install |
| 46 | + |
| 47 | + - name: Configure Git user |
| 48 | + run: | |
| 49 | + git config --global user.email "[email protected]" |
| 50 | + git config --global user.name "Tóth Mihály" |
| 51 | +
|
| 52 | + - name: Ensure target branch exists |
| 53 | + run: | |
| 54 | + git fetch origin |
| 55 | + if git ls-remote --exit-code origin ${{ github.event.inputs.toBranchName }}; then |
| 56 | + git checkout ${{ github.event.inputs.toBranchName }} |
| 57 | + git pull origin ${{ github.event.inputs.toBranchName }} |
| 58 | + else |
| 59 | + git checkout -b ${{ github.event.inputs.toBranchName }} |
| 60 | + git push origin ${{ github.event.inputs.toBranchName }} |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Fetch workspace schema for target branch |
| 64 | + env: |
| 65 | + BRANCH_NAME: ${{ github.event.inputs.toBranchName }} |
| 66 | + BRANCH_URL: ${{ github.event.inputs.toBranchUrl }} |
| 67 | + ACTION_TYPE: ${{ github.event.inputs.actionType }} |
| 68 | + USE_LOCAL_YAML: 'false' |
| 69 | + run: node src/index.js |
| 70 | + |
| 71 | + - name: Clear the repo folder |
| 72 | + run: | |
| 73 | + rm -rf repo |
| 74 | + echo "Cleared the repo folder to ensure a clean state." |
| 75 | +
|
| 76 | + - name: Rebuild the repo folder |
| 77 | + env: |
| 78 | + BRANCH_NAME: ${{ github.event.inputs.toBranchName }} |
| 79 | + BRANCH_URL: ${{ github.event.inputs.toBranchUrl }} |
| 80 | + ACTION_TYPE: ${{ github.event.inputs.actionType }} |
| 81 | + USE_LOCAL_YAML: 'false' |
| 82 | + run: node src/index.js |
| 83 | + |
| 84 | + - name: Commit and push changes to target branch |
| 85 | + run: | |
| 86 | + git add . |
| 87 | + git diff-index --quiet HEAD || git commit -m "Merge from ${{ github.event.inputs.fromBranchName }} to ${{ github.event.inputs.toBranchName }}" |
| 88 | + git push origin ${{ github.event.inputs.toBranchName }} || true |
| 89 | +
|
| 90 | + new: |
| 91 | + if: ${{ github.event.inputs.actionType == 'new' }} |
| 92 | + runs-on: ubuntu-latest |
| 93 | + |
| 94 | + steps: |
| 95 | + - name: Checkout repository |
| 96 | + uses: actions/checkout@v4 |
| 97 | + |
| 98 | + - name: Set up Node.js |
| 99 | + |
| 100 | + with: |
| 101 | + node-version: 'latest' |
| 102 | + |
| 103 | + - name: Install dependencies |
| 104 | + run: npm install |
| 105 | + |
| 106 | + - name: Configure Git user |
| 107 | + run: | |
| 108 | + git config --global user.email "[email protected]" |
| 109 | + git config --global user.name "Tóth Mihály" |
| 110 | +
|
| 111 | + - name: Create new branch and run syncing script |
| 112 | + env: |
| 113 | + BRANCH_NAME: ${{ github.event.inputs.toBranchName || 'prod' }} |
| 114 | + BRANCH_URL: ${{ github.event.inputs.toBranchUrl || '' }} |
| 115 | + ACTION_TYPE: ${{ github.event.inputs.actionType || 'new' }} |
| 116 | + USE_LOCAL_YAML: 'false' |
| 117 | + run: | |
| 118 | + git fetch origin |
| 119 | + if git ls-remote --exit-code origin ${{ github.event.inputs.toBranchName }}; then |
| 120 | + git checkout ${{ github.event.inputs.toBranchName }} |
| 121 | + git pull origin ${{ github.event.inputs.toBranchName }} |
| 122 | + else |
| 123 | + git checkout -b ${{ github.event.inputs.toBranchName }} |
| 124 | + fi |
| 125 | + node src/index.js |
| 126 | + git add . |
| 127 | + git diff-index --quiet HEAD || git commit -m "Initial commit for ${{ github.event.inputs.toBranchName }}" |
| 128 | + git push origin ${{ github.event.inputs.toBranchName }} || true |
0 commit comments