From cf2df0776cdd1d1cecb0e4e3c2079b13736dcca9 Mon Sep 17 00:00:00 2001 From: SirWalross <27106448+SirWalross@users.noreply.github.com> Date: Wed, 15 Jun 2022 23:29:45 +0200 Subject: [PATCH] Add support for gitlab ci --- .github/workflows/convert.yml | 4 ---- .gitlab-ci.yml | 37 +++++++++++++++++++++++++++++++++++ convert.py | 11 ++++++++--- 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.github/workflows/convert.yml b/.github/workflows/convert.yml index 0eea13f..286eaf8 100644 --- a/.github/workflows/convert.yml +++ b/.github/workflows/convert.yml @@ -1,9 +1,6 @@ name: Convert data to .mat file(s) on: - push: - branches: - - "main" schedule: - cron: "0 1 * * *" @@ -27,7 +24,6 @@ jobs: - name: Convert data run: | python3 convert.py - cd out && zip ../data.zip ./* && cd - - name: release uses: "./.github/actions/automatic-releases" with: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..c8a94db --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,37 @@ + +stages: + - convert + - upload + - release + +variables: + PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/my_package/latest/data.zip" + +convert: + stage: convert + image: "python:3.10" + script: + - python3 -m pip install --upgrade pip + - python3 -m pip install numpy scipy + - python3 convert.py + artifacts: + paths: + - data.zip + - CHANGELOG.md + +upload: + stage: upload + image: curlimages/curl:latest + script: + - echo "Compiling the code..." + - echo "Compile complete." + script: + - 'curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file data.zip "${PACKAGE_REGISTRY_URL}"' + +release: + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + script: + - | + release-cli create --name "Data" --tag-name "latest" --description "CHANGELOG.md" \ + --assets-link "{\"name\":\"data.zip\",\"url\":\"${PACKAGE_REGISTRY_URL}\"}" \ \ No newline at end of file diff --git a/convert.py b/convert.py index f0b0cd5..1d03fad 100644 --- a/convert.py +++ b/convert.py @@ -6,8 +6,9 @@ Combines the files from one weak and converts it into a single '.mat' file. from datetime import datetime, timedelta from pathlib import Path import glob -from time import strptime, time -from typing import Dict, Optional +from time import strptime +from typing import Dict +import shutil import numpy as np import scipy.io @@ -47,6 +48,10 @@ for week_start, arr in data.items(): mdict={name: column for name, column in zip(header, np.split(arr, arr.shape[1], axis=1))}, ) +# zip folder +shutil.make_archive("data", "zip", "out") + # Update CHANGELOG.md with open(str(Path.joinpath(Path(__file__).parent, "CHANGELOG.md")), "w+") as f: - f.write("# Messdaten vom Silo von den Wochen:\n" + "\n".join(["- " + key for key in data.keys()])) + f.write("## Messdaten vom Silo von den Wochen:\n" + "\n".join(["- " + key for key in data.keys()])) + -- GitLab