diff --git a/copier.yml b/copier.yml index dd3cedf..73dac4c 100644 --- a/copier.yml +++ b/copier.yml @@ -44,6 +44,11 @@ tool_category: Small Angle Neutron Scattering: small-angle-neutron-scattering Triple-Axis Spectroscopy: spectroscopy +git_remote: + type: str + help: Provide your git remote URL (if not the default, then you will need to email ndip@ornl.gov for help setting up secrets) + default: "https://code.ornl.gov/ndip/tool-sources/{{ tool_category }}/{{ project_name.lower().replace(' ', '-').replace('_', '-') }}" + # --- Nova Application Specific --- # Implicitly GUI if Nova Application is chosen. framework: diff --git a/dockerfiles/.cli-copier-answers.yml b/dockerfiles/.cli-copier-answers.yml index aba7b3a..e0af6f3 100644 --- a/dockerfiles/.cli-copier-answers.yml +++ b/dockerfiles/.cli-copier-answers.yml @@ -1,5 +1,6 @@ # Please do not edit or delete this file. It is needed to be able to update project from template. application_type: Command-line tool +git_remote: https://code.ornl.gov/ndip/tool-sources/generic/cli-tool project_name: CLI Tool python_package: cli-tool tool_category: generic diff --git a/dockerfiles/.library-copier-answers.yml b/dockerfiles/.library-copier-answers.yml index c571aa2..88e3a31 100644 --- a/dockerfiles/.library-copier-answers.yml +++ b/dockerfiles/.library-copier-answers.yml @@ -1,5 +1,6 @@ # Please do not edit or delete this file. It is needed to be able to update project from template. application_type: Library +git_remote: https://code.ornl.gov/ndip/tool-sources/generic/library project_name: Library publish_docs: true publish_to_pypi: true diff --git a/dockerfiles/.minimal-copier-answers.yml b/dockerfiles/.minimal-copier-answers.yml index 616183d..93dd771 100644 --- a/dockerfiles/.minimal-copier-answers.yml +++ b/dockerfiles/.minimal-copier-answers.yml @@ -1,4 +1,5 @@ # Please do not edit or delete this file. It is needed to be able to update project from template. application_type: Minimal +git_remote: https://code.ornl.gov/ndip/tool-sources/generic/minimal project_name: minimal tool_category: generic diff --git a/dockerfiles/.ndip-tool-copier-answers.yml b/dockerfiles/.ndip-tool-copier-answers.yml index dce3cef..8543c89 100644 --- a/dockerfiles/.ndip-tool-copier-answers.yml +++ b/dockerfiles/.ndip-tool-copier-answers.yml @@ -1,5 +1,6 @@ # Please do not edit or delete this file. It is needed to be able to update project from template. application_type: NDIP Tool +git_remote: https://code.ornl.gov/ndip/tool-sources/generic/ndip_tool project_name: ndip_tool python_package: ndip_tool tool_category: generic diff --git a/dockerfiles/.nova-application-copier-answers.yml b/dockerfiles/.nova-application-copier-answers.yml index 3e46986..418c9ea 100644 --- a/dockerfiles/.nova-application-copier-answers.yml +++ b/dockerfiles/.nova-application-copier-answers.yml @@ -1,6 +1,7 @@ # Please do not edit or delete this file. It is needed to be able to update project from template. application_type: Nova Application framework: Trame +git_remote: https://code.ornl.gov/ndip/tool-sources/generic/nova_application multitabs: true project_name: nova_application python_package: nova_application diff --git a/dockerfiles/.tutorial-copier-answers.yml b/dockerfiles/.tutorial-copier-answers.yml index 1d2c80d..8d5b4d0 100644 --- a/dockerfiles/.tutorial-copier-answers.yml +++ b/dockerfiles/.tutorial-copier-answers.yml @@ -1,6 +1,7 @@ # Please do not edit or delete this file. It is needed to be able to update project from template. application_type: Tutorial framework: Trame +git_remote: https://code.ornl.gov/ndip/tool-sources/generic/tutorial multitabs: true project_name: Tutorial python_package: tutorial diff --git a/template_sources/.github/workflows/build-test.yml.j2 b/template_sources/.github/workflows/build-test.yml.j2 new file mode 100644 index 0000000..9acd055 --- /dev/null +++ b/template_sources/.github/workflows/build-test.yml.j2 @@ -0,0 +1,71 @@ +name: Build and Test + +on: push + +concurrency: + group: "{% raw %}${{ github.ref }}{% endraw %}" + cancel-in-progress: true + +env: + NDIP_DOCKER_REPOSITORY: "{% raw %}${{ secrets.NDIP_DOCKER_REPOSITORY }}{% endraw %}" + +jobs: + build-and-test: + runs-on: ubuntu-latest + timeout-minutes: 60 + env: + GIT_STRATEGY: clone + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 20 + lfs: true + - name: Build + uses: docker/build-push-action@v6 + id: build + with: + file: dockerfiles/Dockerfile + load: true + target: source + - name: Run ruff check + run: docker run --rm {% raw %}${{ steps.build.outputs.imageid }}{% endraw %} ruff check + - name: Run format check + run: docker run --rm {% raw %}${{ steps.build.outputs.imageid }}{% endraw %} ruff format --check + - name: Run mypy + run: docker run --rm {% raw %}${{ steps.build.outputs.imageid }}{% endraw %} mypy . + - name: Unit tests + run: docker run --rm {% raw %}${{ steps.build.outputs.imageid }}{% endraw %} pytest + - name: Run coverage + run: docker run --rm {% raw %}${{ steps.build.outputs.imageid }}{% endraw %} sh -c "coverage run && coverage report" + - name: Docs test + run: docker run --rm {% raw %}${{ steps.build.outputs.imageid }}{% endraw %} bash build_docs.sh + + publish-prototype: + runs-on: ubuntu-latest + env: + IMAGE_NAME: savannah.ornl.gov/ndip/tool-sources/{{ tool_category }}/{% include 'name_slug.j2' %}/prototypes + permissions: write-all + steps: + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: {% raw %}${{ secrets.NDIP_DOCKER_REGISTRY }}{% endraw %} + username: {% raw %}${{ secrets.NDIP_DOCKER_USER }}{% endraw %} + password: {% raw %}${{ secrets.NDIP_DOCKER_PASSWORD }}{% endraw %} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Checkout repo + uses: actions/checkout@v4 + - name: Build and push + uses: docker/build-push-action@v6 + with: + file: dockerfiles/Dockerfile + push: true + tags: {% raw %}${{ env.IMAGE_NAME }}:${{ github.sha }}{% endraw %} diff --git a/template_sources/.github/workflows/release-version.yml.j2 b/template_sources/.github/workflows/release-version.yml.j2 new file mode 100644 index 0000000..8fabfbd --- /dev/null +++ b/template_sources/.github/workflows/release-version.yml.j2 @@ -0,0 +1,56 @@ +name: Release Image + +on: + workflow_dispatch: + +jobs: + tag-release: + runs-on: ubuntu-latest + timeout-minutes: 60 + permissions: write-all + env: + GIT_STRATEGY: clone + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 20 + lfs: true + - name: Parse version + run: {% raw %}echo "VERSION=$(cat pyproject.toml | grep "version =" | head -n 1 | awk '{ print $3 }' | tr -d '"')" >> $GITHUB_ENV{% endraw %} + - name: Create release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} + with: + tag_name: {% raw %}${{ env.VERSION }}{% endraw %} + release_name: {% raw %}${{ env.VERSION }}{% endraw %} + + publish-release: + runs-on: ubuntu-latest + env: + IMAGE_NAME: savannah.ornl.gov/ndip/tool-sources/{{ tool_category }}/{% include 'name_slug.j2' %} + permissions: write-all + steps: + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: {% raw %}${{ secrets.NDIP_DOCKER_REGISTRY }}{% endraw %} + username: {% raw %}${{ secrets.NDIP_DOCKER_USER }}{% endraw %} + password: {% raw %}${{ secrets.NDIP_DOCKER_PASSWORD }}{% endraw %} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Checkout repo + uses: actions/checkout@v4 + - name: Parse version + run: echo "VERSION=$(cat pyproject.toml | grep "version =" | head -n 1 | awk '{ print $3 }' | tr -d '"')" >> $GITHUB_ENV + - name: Check image already exists + run: if [ -n "$(docker manifest inspect {% raw %}${{ env.IMAGE_NAME }}:${{ env.VERSION }}{% endraw %})" ]; then echo "Image already exists, update the version and try again." && exit 1; fi + - name: Build and push + uses: docker/build-push-action@v6 + with: + file: dockerfiles/Dockerfile + push: true + tags: {% raw %}${{ env.IMAGE_NAME }}:latest,${{ env.IMAGE_NAME }}:${{ env.VERSION }}{% endraw %} \ No newline at end of file diff --git a/template_sources/scripts/{% if application_type == 'Minimal' %}init-repo.sh{% endif %}.j2 b/template_sources/scripts/{% if application_type == 'Minimal' %}init-repo.sh{% endif %}.j2 index 83c8124..3eafbe3 100644 --- a/template_sources/scripts/{% if application_type == 'Minimal' %}init-repo.sh{% endif %}.j2 +++ b/template_sources/scripts/{% if application_type == 'Minimal' %}init-repo.sh{% endif %}.j2 @@ -9,7 +9,7 @@ TOOL_CATEGORY="{{ tool_category }}" PROJECT_NAME_RAW="{{ project_name }}" # Slugify project name for URL (lowercase, replace space/underscore with dash) PROJECT_SLUG=$(echo "$PROJECT_NAME_RAW" | tr '[:upper:]' '[:lower:]' | sed 's/[ _]/-/g') -REMOTE_URL="https://code.ornl.gov/ndip/tool-sources/${TOOL_CATEGORY}/${PROJECT_SLUG}" +REMOTE_URL="{{ git_remote }}" INITIAL_COMMIT_MSG="Initial commit from NOVA Application Template (Minimal)" # --- Functions --- diff --git a/template_sources/scripts/{% if application_type in ['Nova Application', 'NDIP Tool', 'Tutorial'] %}git_utils.py{% endif %}.j2 b/template_sources/scripts/{% if application_type in ['Nova Application', 'NDIP Tool', 'Tutorial'] %}git_utils.py{% endif %}.j2 index 70935b4..9fc3ad0 100644 --- a/template_sources/scripts/{% if application_type in ['Nova Application', 'NDIP Tool', 'Tutorial'] %}git_utils.py{% endif %}.j2 +++ b/template_sources/scripts/{% if application_type in ['Nova Application', 'NDIP Tool', 'Tutorial'] %}git_utils.py{% endif %}.j2 @@ -12,8 +12,7 @@ def init_repository() -> None: This function will: - Initialize a git repository if one doesn't exist. - Set the default branch to 'main'. - - Add or update the 'origin' remote to point to the GitLab repository: - https://code.ornl.gov/ndip/tool-sources/{{ tool_category }}/{{ project_name.lower().replace(' ', '-').replace('_', '-') }} + - Add or update the 'origin' remote to point to the GitLab repository: {{ git_remote }} - Stage all files. - Create an initial commit if no commits exist. @@ -22,8 +21,7 @@ def init_repository() -> None: try: # Determine repository path # We need to organize the groups under tool sources and provide them an option of location - remote_url = "https://code.ornl.gov/ndip/tool-sources/{{ tool_category }}/" - remote_url += "{{ project_name.lower().replace(' ', '-').replace('_', '-') }}" + remote_url = "{{ git_remote }}" # --- Confirmation Step --- print("\n--- Git Repository Setup Plan ---") diff --git a/template_sources/xml/tool.xml.j2 b/template_sources/xml/tool.xml.j2 index 20dd54b..98ea8cb 100644 --- a/template_sources/xml/tool.xml.j2 +++ b/template_sources/xml/tool.xml.j2 @@ -31,6 +31,6 @@ This is a Galaxy tool for {{ project_name }}. - For more information, see the repository: https://code.ornl.gov/ndip/tool-sources/{{ tool_category }}/{{ project_name.lower().replace(' ', '-').replace('_', '-') }} + For more information, see the repository: {{ git_remote }} ]]> \ No newline at end of file