bitcoin-tools / nodebuilder

Run a secure Bitcoin Core node with ease.
MIT No Attribution
7 stars 1 forks source link

[FEAT] Avoid repeated code with environmental variables #695

Closed bitcoin-tools closed 6 months ago

bitcoin-tools commented 6 months ago

Describe the problem you're having

Set environmental variables for the job only:

env:
  UBUNTU_CHECK_VERSION_COMMAND: grep "VERSION\|ID" /etc/os-release
  UBUNTU_REMOVE_SNAP_COMMAND: sudo apt remove --assume-yes snap
  UBUNTU_INSTALL_UPGRADES_COMMAND: >-
    sleep $(echo "scale=3; $RANDOM / 32768 * 10" | bc)
    && sudo apt-get update --option 'Acquire::Retries=5'
    && sudo NEEDRESTART_MODE=a apt-get dist-upgrade --assume-yes --option 'Acquire::Retries=5'
  UBUNTU_CACHE_PATH: |
    /var/cache/apt/archives/*.deb
    /var/lib/apt/lists/*.ubuntu.com_ubuntu_dists_*
    /var/lib/apt/lists/download.docker.com_linux_ubuntu_dists_*
    /var/lib/apt/lists/dl.google.com_linux_chrome_deb_dists_*
    /var/lib/apt/lists/packages.microsoft.com_repos_code_dists_*
    /var/lib/apt/lists/pkg.cloudflareclient.com_dists_*
  MACOS_CHECK_VERSION_COMMAND: sw_vers | grep Version | awk '{print $2}'

then use the ends in the matrix strategy

matrix:
  include:
    - os: ubuntu-22.04
      os-friendly-name: Ubuntu 22 [x86_64]
      check-version-command: ${{ env.UBUNTU_CHECK_VERSION_COMMAND }}
      remove-snap-command: ${{ env.UBUNTU_REMOVE_SNAP_COMMAND }}
      install-upgrades-command: ${{ env.UBUNTU_INSTALL_UPGRADES_COMMAND }}
      cache-path: ${{ env.UBUNTU_CACHE_PATH }}
    - os: ubuntu-latest
      os-friendly-name: Ubuntu LTS [x86_64]
      check-version-command: ${{ env.UBUNTU_CHECK_VERSION_COMMAND }}
      remove-snap-command: ${{ env.UBUNTU_REMOVE_SNAP_COMMAND }}
      install-upgrades-command: ${{ env.UBUNTU_INSTALL_UPGRADES_COMMAND }}
      cache-path: ${{ env.UBUNTU_CACHE_PATH }}
    - os: macos-13
      os-friendly-name: macOS 13 [x86_64]
      check-version-command: ${{ env.MACOS_CHECK_VERSION_COMMAND }}
    - os: macos-14
      os-friendly-name: macOS 14 [arm64]
      check-version-command: ${{ env.MACOS_CHECK_VERSION_COMMAND }}

Describe the solution you'd like to see

Describe any alternatives you've considered

Additional context

bitcoin-tools commented 6 months ago

Limited by GitHub Actions. Can't do.