Repository: LLNL/PyDV (language: python)

Issue:
Script for tag and prelease
- [x] Create a script that iterates the version number throughout the code with options for major, minor, and patch. May need to centralize the version and have everything read from that.

- [x] Create a PR action that ensures that the version has been changed.
*There may be a way to do this, but for now I will just add this as a checkbox in the template.

- [x] A PR template checkbox for updating the release notes.

- [x] Merge action that tags and prereleases.

In epic #225


Discussion / hints:

Fix patch:
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000..6f06c8d
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,16 @@
+### Description
+
+Resolves # <!--(*If this PR is unrelated to a ticket, please erase this line*)-->
+
+<!-- A summary of the change -->
+
+### Checklist:
+
+<!-- Remove any that are not applicable -->
+
+- [ ] I have added/updated an image test.
+- [ ] I have run the image tests on RZ and they pass.
+- [ ] I have made corresponding changes to the documentation.
+- [ ] I have build the docs on sphinx and they look correct.
+- [ ] I have updated the release notes.
+- [ ] I have run `pydv/scripts/update_version_and_date.py <major, minor, patch>`.
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index a77dc38..d82e863 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -4,41 +4,21 @@ name: Release
 on:
   push:
     branches: [ master ]
-  # push:
-  #   branches: [ master, pydv-230-script-for-tag-and-prerelease ]
 
 jobs:
-  build:
+  release:
     name: Create Release
     runs-on: ubuntu-latest
     steps:
       - name: Checkout code
-        uses: actions/checkout@master
+        uses: actions/checkout@v2
       - name: Create Release
         id: create_release
         uses: actions/create-release@v1
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
         with:
-          tag_name: ${{ github.ref }}
-          release_name: Release ${{ github.ref }}
-          body: |
-            Changes in this Release
-            - First Change
-            - Second Change
+          tag_name: pydv-3.0.4
+          release_name: PyDV 3.0.4
           draft: false
           prerelease: false
-
-# # only trigger on pull request closed events
-# on:
-#   pull_request:
-#     types: [ closed ]
-
-# jobs:
-#   merge_job:
-#     # this job will only run if the PR has been merged
-#     if: github.event.pull_request.merged == true
-#     runs-on: ubuntu-latest
-#     steps:
-#     - run: |
-#         echo PR #${{ github.event.number }} has been merged
\ No newline at end of file
diff --git a/pydv/scripts/date.txt b/pydv/scripts/date.txt
new file mode 100644
index 0000000..1465de9
--- /dev/null
+++ b/pydv/scripts/date.txt
@@ -0,0 +1,1 @@
+04.07.2021
\ No newline at end of file
diff --git a/pydv/scripts/update_version_and_date.py b/pydv/scripts/update_version_and_date.py
new file mode 100644
index 0000000..4479f7d
--- /dev/null
+++ b/pydv/scripts/update_version_and_date.py
@@ -0,0 +1,64 @@
+
+from datetime import date
+import os
+import argparse
+import fileinput
+
+SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
+SOURCE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+# Get the version number from the version file
+version_file = os.path.join(SCRIPTS_DIR, 'version.txt')
+with open(version_file, 'r') as fp:
+    version = fp.read()
+    version_list = version.split('.')
+    major, minor, patch = int(version_list[0]), int(version_list[1]), int(version_list[2])
+
+# Determine the new version from the specified type of change
+parser = argparse.ArgumentParser()
+parser.add_argument('type', choices=['major', 'minor', 'patch'])
+args = parser.parse_args().type
+if args == 'major':
+    major += 1
+    minor = 0
+    patch = 0
+elif args == 'minor':
+    minor += 1
+    patch = 0
+elif args == 'patch':
+    patch += 1
+new_version = f'{major}.{minor}.{patch}'
+
+# Replace the version everwhere in the source code where it appears.
+files = [
+    os.path.join(ROOT_DIR, 'setup.py'),
+    os.path.join(ROOT_DIR, '.github', 'workflows', 'release.yml'),
+    os.path.join(SOURCE_DIR, 'pdvplot.py'),
+    os.path.join(SOURCE_DIR, 'pdv.py'),
+    os.path.join(SOURCE_DIR, 'docs', 'conf.py'),
+    os.path.join(SCRIPTS_DIR, 'version.txt'),
+]
+for afile in files:
+    with fileinput.FileInput(afile, inplace=True) as fp:
+        for line in fp:
+            print(line.replace(version, new_version), end='')
+
+# Special case: the conf.py file also wants a representation of just major.minor
+with fileinput.FileInput(os.path.join(SOURCE_DIR, 'docs', 'conf.py'), inplace=True) as fp:
+    for line in fp:
+        print(line.replace(f'{version_list[0]}.{version_list[1]}', f'{major}.{minor}'), end='')
+
+# Replace the date
+with open(os.path.join(SCRIPTS_DIR, 'date.txt')) as fp:
+    old_date = fp.read()
+new_date = date.today()
+new_date = f'{new_date.month:02d}.{new_date.day:02d}.{new_date.year:04d}'
+files = [
+    os.path.join(SOURCE_DIR, 'pdv.py'),
+    os.path.join(SCRIPTS_DIR, 'date.txt'),
+]
+for afile in files:
+    with fileinput.FileInput(afile, inplace=True) as fp:
+        for line in fp:
+            print(line.replace(old_date, new_date), end='')
diff --git a/pydv/scripts/version.txt b/pydv/scripts/version.txt
new file mode 100644
index 0000000..b38ebbf
--- /dev/null
+++ b/pydv/scripts/version.txt
@@ -0,0 +1,1 @@
+3.0.4
\ No newline at end of file


Test patch:
diff --git a/.github/workflows/python-app.yml b/.github/workflows/build-and-test.yml
similarity index 97%
rename from .github/workflows/python-app.yml
rename to .github/workflows/build-and-test.yml
index b1db2d0..fbb0911 100644
--- a/.github/workflows/python-app.yml
+++ b/.github/workflows/build-and-test.yml
@@ -1,7 +1,7 @@
 # This workflow will install Python dependencies, run tests and lint with a single version of Python
 # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
 
-name: Python application
+name: Build and Test
 
 on:
   push: