diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml index ffb36213..57b752ef 100644 --- a/.github/workflows/bump_version.yml +++ b/.github/workflows/bump_version.yml @@ -1,3 +1,5 @@ +# Bump a patch version with poetry when a pull requst is merged + name: bump patch version using poetry on: @@ -9,32 +11,8 @@ on: jobs: bump-up-version: - runs-on: ubuntu-latest if: github.event.pull_request.merged == true - steps: - - name: checkout code - uses: actions/checkout@v4 - with: - token: ${{ secrets.VERSION_DECOIMPACT }} - - name: install python - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - name: Install poetry - uses: abatilo/actions-poetry@v2 - with: - poetry-version: 1.4.2 - - name: bump version and update template_input.yaml - run: | - git config user.name github-actions - git config user.email github-actions@github.com - poetry version patch - PROJECT_VERSION=$(poetry version --short) - sed -i "1 s/.*/version: $PROJECT_VERSION/" template_input.yaml - - name: commit changes - run: | - PROJECT_VERSION=$(poetry version --short) - git add template_input.yaml - git add pyproject.toml - git commit -m "bump patch version: $PROJECT_VERSION" - git push + secrets: inherit + uses: ./.github/workflows/version_upgrade.yml + with: + release_type: patch diff --git a/.github/workflows/docker_image.yml b/.github/workflows/docker_image.yml new file mode 100644 index 00000000..ecb7d806 --- /dev/null +++ b/.github/workflows/docker_image.yml @@ -0,0 +1,63 @@ +# This workflow should be triggered when a release is done (workflow_call) +# And also need to be able to run manually (workflow_dispatch). It uses +# the current version from poetry as a tag for the docker container and +# pushes the container to the GitHub Container Registry +# (ghcr.io/deltares/d-ecoimpact:latest). + +name: "Publish to GHCR" + +on: + workflow_call: + inputs: + project_version: + required: true + default: false + type: string + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + # Convert Deltares/D-EcoImpact to deltares/d-ecoimpact because + # image name can't support uppercase + - name: downcase REPO + run: | + echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} + - name: checkout code + uses: actions/checkout@v4 + with: + token: ${{ secrets.VERSION_DECOIMPACT || github.token }} + fetch-depth: 0 + - name: install python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + - name: Install poetry + uses: abatilo/actions-poetry@v2 + with: + poetry-version: 1.4.2 + - name: Get current version + id: get-version + if: ${{ env.PROJECT_VERSION }} == false + run: | + PROJECT_VERSION=$(poetry version --short) + echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_OUTPUT + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push the Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.project_version || steps.get-version.outputs.PROJECT_VERSION }} diff --git a/.github/workflows/mkdocs_documentation.yml b/.github/workflows/mkdocs_documentation.yml new file mode 100644 index 00000000..40e7adb8 --- /dev/null +++ b/.github/workflows/mkdocs_documentation.yml @@ -0,0 +1,34 @@ +name: Create Mkdocs documentation + +on: + workflow_call: + inputs: + project_version: + required: true + type: string + +jobs: + create-docs: + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v4 + with: + token: ${{ secrets.VERSION_DECOIMPACT }} + fetch-depth: 0 + - name: install python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + - name: Install poetry + uses: abatilo/actions-poetry@v2 + with: + poetry-version: 1.4.2 + - name: Install Dependencies + run: poetry install + - name: Create new version of mkdocs and publish + run: | + git config user.name github-actions + git config user.email github-actions@github.com + poetry run mike deploy --push --update-aliases ${{ inputs.project_version }} latest + poetry run mike set-default --push latest \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bec1f408..d9d6e58c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,6 +1,5 @@ -# This workflow should be triggered when a release of the main is needed. -# It creates a tag and regenerates the documentation to generate a release. -# It does not bump the version number, that happens for the merged pull request. +# This workflow should be triggered when a release of the main is needed. +# It creates a tag and regenerates the documentation to generate a release. name: Release major or minor version (create tag and documentation) @@ -16,49 +15,35 @@ on: - major jobs: + bump-up-version: + secrets: inherit + uses: ./.github/workflows/version_upgrade.yml + with: + release_type: ${{ github.event.inputs.release_type }} + create-release: runs-on: ubuntu-latest + needs: bump-up-version steps: - - name: checkout code - uses: actions/checkout@v4 - with: - token: ${{ secrets.VERSION_DECOIMPACT }} - fetch-depth: 0 - - name: install python - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - name: Install poetry - uses: abatilo/actions-poetry@v2 - with: - poetry-version: 1.4.2 - - name: bump version and update template_input.yaml - run: | - git config user.name github-actions - git config user.email github-actions@github.com - poetry version ${{ github.event.inputs.release_type }} - PROJECT_VERSION=$(poetry version --short) - echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV - sed -i "1 s/.*/version: $PROJECT_VERSION/" template_input.yaml - - name: commit changes - run: | - PROJECT_VERSION=$(poetry version --short) - git add template_input.yaml - git add pyproject.toml - git commit -m "bump version: $PROJECT_VERSION" - git push - name: Create Release uses: actions/create-release@latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token with: - tag_name: ${{ env.PROJECT_VERSION }} - release_name: Release ${{ env.PROJECT_VERSION }} + tag_name: ${{ needs.bump-up-version.outputs.project_version }} + release_name: Release ${{ needs.bump-up-version.outputs.project_version }} draft: false prerelease: false - - name: Install Dependencies - run: poetry install - - name: Create new version of mkdocs and publish - run: | - poetry run mike deploy --push --update-aliases ${PROJECT_VERSION} latest - poetry run mike set-default --push latest + + create-documentation: + needs: bump-up-version + secrets: inherit + uses: ./.github/workflows/mkdocs_documentation.yml + with: + project_version: ${{ needs.bump-up-version.outputs.project_version }} + + docker-build: + needs: bump-up-version + uses: ./.github/workflows/docker_image.yml + with: + project_version: ${{ needs.bump-up-version.outputs.project_version }} diff --git a/.github/workflows/version_upgrade.yml b/.github/workflows/version_upgrade.yml new file mode 100644 index 00000000..4778e3a2 --- /dev/null +++ b/.github/workflows/version_upgrade.yml @@ -0,0 +1,52 @@ +# This workflow is used in bump_version and release workflows. It +# install poetry and updates the version of the code. It gives back +# the new version which can be used in the consequent workflows. + +name: Version upgrade with poetry + +on: + workflow_call: + inputs: + release_type: + required: true + type: string + outputs: + project_version: + value: ${{ jobs.upgrade-version.outputs.job_output_version}} + + +jobs: + upgrade-version: + runs-on: ubuntu-latest + outputs: + job_output_version: ${{ steps.get-version.outputs.PROJECT_VERSION}} + steps: + - name: checkout code + uses: actions/checkout@v4 + with: + token: ${{ secrets.VERSION_DECOIMPACT }} + fetch-depth: 0 + - name: install python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + - name: Install poetry + uses: abatilo/actions-poetry@v2 + with: + poetry-version: 1.4.2 + - name: bump version and update template_input.yaml + id: get-version + run: | + git config user.name github-actions + git config user.email github-actions@github.com + poetry version ${{ inputs.release_type }} + PROJECT_VERSION=$(poetry version --short) + echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_OUTPUT + sed -i "1 s/.*/version: $PROJECT_VERSION/" template_input.yaml + - name: commit changes + run: | + PROJECT_VERSION=$(poetry version --short) + git add template_input.yaml + git add pyproject.toml + git commit -m "bump ${{ inputs.release_type }} version: ${{ steps.get-version.outputs.PROJECT_VERSION }}" + git push \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index fbc3b094..b6aea4dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "decoimpact" -version = "0.3.14" +version = "0.5.0" description = "A Python based kernel to perform spatial (environmental) impact assessment. Based on knowledge rules applied to model output and/or measurements." authors = ["Deltares"] readme = "README.md" diff --git a/template_input.yaml b/template_input.yaml index 8a135197..06609528 100644 --- a/template_input.yaml +++ b/template_input.yaml @@ -1,4 +1,4 @@ -version: 0.3.14 +version: 0.5.0 input-data: - dataset: