Unverified Commit a1ad4cf3 authored by liziwl's avatar liziwl Committed by GitHub
Browse files

Merge pull request #35 from SUSTech-CRA/hotfix/flow

加入格式化预构建的元数据脚本
parents 754f78a1 d5f99df4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -19,6 +19,15 @@ jobs:
      - name: Checkout
        uses: actions/checkout@v2

      - uses: actions/setup-python@v2
        if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
        with:
          python-version: '3.9'

      - name: Meta-data normalization
        if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
        run: python test/update-dist.py --dev

      - name: run texlive docker container
        uses: docker://texlive/texlive:TL2020-historic
        # https://hub.docker.com/r/texlive/texlive
+7 −0
Original line number Diff line number Diff line
@@ -9,6 +9,13 @@ jobs:
      - name: Checkout
        uses: actions/checkout@v2

      - uses: actions/setup-python@v2
        with:
          python-version: '3.9'

      - name: Meta-data normalization
        run: python test/update-dist.py --dev

      - name: run texlive docker container
        uses: docker://texlive/texlive:TL2020-historic
        # https://hub.docker.com/r/texlive/texlive
+46 −14
Original line number Diff line number Diff line
import os
import re
import sys

filename = "sustechthesis.dtx"
new_version = "1.3.7"
new_date = "2021/11/02"

def change_meta(version, date):
    with open(filename, "r", encoding="utf-8") as f1:
        with open("{filename}.bak", "w", encoding="utf-8") as f2:
            for line in f1:
                if "Southern University of Science and Technology Thesis Template" in line:
                line = re.sub("\d\.\d\.\d", new_version, line)
                line = re.sub("\d{4}/\d{2}/\d{2}", new_date, line)
                    print(line)
                    line = re.sub("\d\.\d\.\d", version, line)
                    line = re.sub("\d{4}/\d{2}/\d{2}", date, line)
                    f2.write(line)
                    print(line)
                elif "\\def\\version" in line:
                line = re.sub("\d\.\d\.\d", new_version, line)
                    print(line)
                    line = re.sub("\d\.\d\.\d", version, line)
                    f2.write(line)
                    print(line)
                else:
                    f2.write(line)
            os.remove(filename)
            os.rename("{filename}.bak", filename)


if __name__ == "__main__":
    import argparse
    import time
    parser = argparse.ArgumentParser()
    parser.add_argument("--version", "-v", default=new_version,
                        help='release version')
    parser.add_argument("--date", "-d", default=new_date,
                        help='release date')
    parser.add_argument("--dev", action='store_true',
                        help='change the meta-data for develop build')
    args = parser.parse_args()

    if args.dev:
        now_date = time.strftime("%Y/%m/%d", time.localtime())
        dev_version = "DEV.BUILD"
        try:
            git_head_sha = os.popen(r"git log -1 --format='%H'").readlines()[0]
        except:
            git_head_sha = "NAN.SHA"
        if git_head_sha:
            dev_version = f"{git_head_sha[:7].upper()}.{dev_version}"
        change_meta(dev_version, now_date)
    else:
        change_meta(args.version, args.date)