Skip to content

Commit

Permalink
Merge pull request #546 from modoboa/feature/versioning
Browse files Browse the repository at this point in the history
Added version check
  • Loading branch information
tonioo authored Apr 24, 2024
2 parents 0f7a636 + 8fec73e commit 2f692e6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 12 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9, '3.10', '3.11']
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r test-requirements.txt
- name: Run tests
if: ${{ matrix.python-version != '3.9' }}
if: ${{ matrix.python-version != '3.11' }}
run: |
python tests.py
- name: Run tests and coverage
if: ${{ matrix.python-version == '3.9' }}
if: ${{ matrix.python-version == '3.11' }}
run: |
coverage run tests.py
- name: Upload coverage result
if: ${{ matrix.python-version == '3.9' }}
uses: actions/upload-artifact@v2
if: ${{ matrix.python-version == '3.11' }}
uses: actions/upload-artifact@v4
with:
name: coverage-results
path: .coverage
Expand All @@ -42,16 +42,16 @@ jobs:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.11'
- name: Install dependencies
run: |
pip install codecov
- name: Download coverage results
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: coverage-results
- name: Report coverage
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/versioning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Update version file

on:
push:
branches: [ master ]

jobs:
update-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
ref: ${{ github.head_ref }}
- name: Overwrite file
uses: "DamianReeves/write-file-action@master"
with:
path: version.txt
write-mode: overwrite
contents: ${{ github.sha }}

- name: Commit & Push
uses: Andro999b/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref_name }}
force: true
message: '[GitHub Action] Updated version file'
37 changes: 37 additions & 0 deletions checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Checks to be performed before any install or upgrade"""

import sys
from urllib.request import urlopen

from modoboa_installer import utils


def check_version():
local_version = ""
with open("version.txt", "r") as version:
local_version = version.readline()
remote_version = ""
with urlopen("https://raw.githubusercontent.com/modoboa/modoboa-installer/master/version.txt") as r_version:
remote_version = r_version.read().decode()
if local_version == "" or remote_version == "":
utils.printcolor(
"Could not check that your installer is up-to-date: "
f"local version: {local_version}, "
f"remote version: {remote_version}",
utils.YELLOW
)
if remote_version != local_version:
utils.error(
"Your installer seems outdated.\n"
"Check README file for instructions about how to update.\n"
"No support will be provided without an up-to-date installer!"
)
answer = utils.user_input("Continue anyway? (Y/n) ")
if not answer.lower().startswith("y"):
sys.exit(0)
else:
utils.success("Installer seems up to date!")


def handle():
check_version()
12 changes: 11 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import ConfigParser as configparser
import sys

import checks
from modoboa_installer import compatibility_matrix
from modoboa_installer import constants
from modoboa_installer import package
Expand Down Expand Up @@ -168,7 +169,10 @@ def main(input_args):
"--restore", type=str, metavar="path",
help="Restore a previously backup up modoboa instance on a NEW machine. "
"You MUST provide backup directory"
)
),
parser.add_argument(
"--skip-checks", action="store_true", default=False,
help="Skip the checks the installer performs initially")
parser.add_argument("domain", type=str,
help="The main domain of your future mail server")
args = parser.parse_args(input_args)
Expand All @@ -189,6 +193,12 @@ def main(input_args):

utils.success("Welcome to Modoboa installer!\n")

# Checks
if not args.skip_checks:
utils.printcolor("Checking the installer...", utils.BLUE)
checks.handle()
utils.success("Checks complete")

is_config_file_available, outdate_config = utils.check_config_file(
args.configfile, args.interactive, args.upgrade, args.backup, is_restoring)

Expand Down

0 comments on commit 2f692e6

Please sign in to comment.