From eb72f3cd3ab7a3ce0ace6ec42e619d163e47a874 Mon Sep 17 00:00:00 2001 From: Marek Rusinowski Date: Mon, 10 Feb 2025 21:02:03 +0100 Subject: [PATCH] Refactor CI workflow to improve code reuse --- .github/actions/scripts-setup/action.yaml | 39 ++++++ .github/workflows/ci.yaml | 141 ++++------------------ .github/workflows/sync_map.yaml | 15 +-- 3 files changed, 65 insertions(+), 130 deletions(-) create mode 100644 .github/actions/scripts-setup/action.yaml diff --git a/.github/actions/scripts-setup/action.yaml b/.github/actions/scripts-setup/action.yaml new file mode 100644 index 0000000..8780049 --- /dev/null +++ b/.github/actions/scripts-setup/action.yaml @@ -0,0 +1,39 @@ +name: Setup maps-metadata scripts +inputs: + cache-name: + description: Name od cache + required: true + download-artifacts: + description: Whatever to try to fetch pre-build artifact for usage in CI workflow + required: false + default: 'true' +runs: + using: "composite" + steps: + - name: Download artifacts + if: ${{ inputs.download-artifacts == 'true' }} + uses: actions/download-artifact@v4 + with: + name: gen-artifacts + path: gen + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.11 + cache: pip + cache-dependency-path: scripts/py/requirements.txt + - uses: actions/setup-node@v4 + with: + node-version: 22.11 + cache: npm + cache-dependency-path: scripts/js/package-lock.json + - uses: actions/cache@v4 + if: ${{ !env.ACT }} + with: + path: .maps-cache + key: maps-cache-cache-v2-${{ inputs.cache-name }}-${{ github.sha }} + restore-keys: | + maps-cache-cache-v2-${{ inputs.cache-name }}- + - name: Install dependencies + shell: bash + run: ./scripts/install.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3e9fa38..fd89c7d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,26 +25,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup Python - uses: actions/setup-python@v5 + - uses: ./.github/actions/scripts-setup with: - python-version: 3.11 - cache: pip - cache-dependency-path: scripts/py/requirements.txt - - uses: actions/setup-node@v4 - with: - node-version: 22.11 - cache: npm - cache-dependency-path: scripts/js/package-lock.json - - uses: actions/cache@v4 - if: ${{ !env.ACT }} - with: - path: .maps-cache - key: maps-cache-cache-v2-build-${{ github.sha }} - restore-keys: | - maps-cache-cache-v2-build- - - name: Install dependencies - run: ./scripts/install.sh + cache-name: build + download-artifacts: 'false' - name: Build run: source .envrc && make -j $(nproc) - name: Test @@ -89,31 +73,9 @@ jobs: if: vars.ENABLE_BYAR_CHOBBY_PUSH && ((github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch') steps: - uses: actions/checkout@v4 - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: gen-artifacts - path: gen - - name: Setup Python - uses: actions/setup-python@v5 + - uses: ./.github/actions/scripts-setup with: - python-version: 3.11 - cache: pip - cache-dependency-path: scripts/py/requirements.txt - - uses: actions/setup-node@v4 - with: - node-version: 22.11 - cache: npm - cache-dependency-path: scripts/js/package-lock.json - - uses: actions/cache@v4 - if: ${{ !env.ACT }} - with: - path: .maps-cache - key: maps-cache-cache-v2-chobby-${{ github.sha }} - restore-keys: | - maps-cache-cache-v2-chobby- - - name: Install dependencies - run: ./scripts/install.sh + cache-name: chobby - name: Checkout BYAR-Chobby uses: actions/checkout@v4 with: @@ -127,23 +89,13 @@ jobs: cp gen/mapDetails.lua BYAR-Chobby/LuaMenu/configs/gameConfig/byar/mapDetails.lua cp gen/mapBoxes.conf BYAR-Chobby/LuaMenu/configs/gameConfig/byar/savedBoxes.dat - name: Commit and push - run: | - cd BYAR-Chobby - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - git remote -v - echo "[+] Git add" - git add . - echo "[+] Git status" - git status - if git diff-index --quiet HEAD; then - echo "No changes to commit" - exit 0 - fi - echo "[+] Git commit" - git commit -m $'Automatic update of maps from maps-metadata\n\nFrom commit ${{ github.repository }}@${{ github.sha }}' - echo "[+] Git push" - git push + uses: stefanzweifel/git-auto-commit-action@v5 + with: + repository: BYAR-Chobby + commit_message: | + Automatic update of maps from maps-metadata + + From commit ${{ github.repository }}@${{ github.sha }} deploy-spads-config: runs-on: ubuntu-latest needs: build-and-test @@ -169,54 +121,22 @@ jobs: cp gen/mapBattlePresets.conf spads_config_bar/etc/mapBattlePresets.conf python3 scripts/py/update_spads_conf.py spads_config_bar/etc/spads_cluster.conf - name: Commit and push - run: | - cd spads_config_bar - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - git remote -v - echo "[+] Git add" - git add . - echo "[+] Git status" - git status - if git diff-index --quiet HEAD; then - echo "No changes to commit" - exit 0 - fi - echo "[+] Git commit" - git commit -m $'Automatic update of maps from maps-metadata\n\nFrom commit ${{ github.repository }}@${{ github.sha }}' - echo "[+] Git push" - git push + uses: stefanzweifel/git-auto-commit-action@v5 + with: + repository: spads_config_bar + commit_message: | + Automatic update of maps from maps-metadata + + From commit ${{ github.repository }}@${{ github.sha }} deploy-website: runs-on: ubuntu-latest needs: build-and-test if: vars.WEBFLOW_COLLECTION_ID && ((github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'workflow_dispatch') steps: - uses: actions/checkout@v4 - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: gen-artifacts - path: gen - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: 3.11 - cache: pip - cache-dependency-path: scripts/py/requirements.txt - - uses: actions/setup-node@v4 - with: - node-version: 22.11 - cache: npm - cache-dependency-path: scripts/js/package-lock.json - - uses: actions/cache@v4 - if: ${{ !env.ACT }} + - uses: ./.github/actions/scripts-setup with: - path: .maps-cache - key: maps-cache-cache-v2-website-${{ github.sha }} - restore-keys: | - maps-cache-cache-v2-website- - - name: Install dependencies - run: ./scripts/install.sh + cache-name: website - name: Push to website uses: nick-fields/retry@v3 with: @@ -238,24 +158,9 @@ jobs: id-token: write steps: - uses: actions/checkout@v4 - - name: Download artifacts - uses: actions/download-artifact@v4 - with: - name: gen-artifacts - path: gen - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: 3.11 - cache: pip - cache-dependency-path: scripts/py/requirements.txt - - uses: actions/setup-node@v4 + - uses: ./.github/actions/scripts-setup with: - node-version: 22.11 - cache: npm - cache-dependency-path: scripts/js/package-lock.json - - name: Install dependencies - run: ./scripts/install.sh + cache-name: gdrive - name: Authenticate to Google Cloud id: auth uses: google-github-actions/auth@v2 diff --git a/.github/workflows/sync_map.yaml b/.github/workflows/sync_map.yaml index a79ab4c..87e48a3 100644 --- a/.github/workflows/sync_map.yaml +++ b/.github/workflows/sync_map.yaml @@ -46,19 +46,10 @@ jobs: - uses: actions/checkout@v4 with: ssh-key: ${{ secrets.SSH_SELF_DEPLOY_KEY }} - - name: Setup Python - uses: actions/setup-python@v5 + - uses: ./.github/actions/scripts-setup with: - python-version: 3.11 - cache: pip - cache-dependency-path: scripts/py/requirements.txt - - uses: actions/setup-node@v4 - with: - node-version: 22.11 - cache: npm - cache-dependency-path: scripts/js/package-lock.json - - name: Install dependencies - run: ./scripts/install.sh + cache-name: sync_map + download-artifacts: 'false' - name: Authenticate to Google Cloud id: auth uses: google-github-actions/auth@v2