diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 770ab505..6b0860d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,20 +1,20 @@ name: Release on: - workflow_dispatch: - inputs: - version: - description: 'Semantic version for the release (X.Y.Z)' - required: true - type: string + push: + branches: main jobs: release: + if: startsWith(github.event.head_commit.message, 'Copernicus Marine Release') runs-on: self-hosted steps: - name: Check out code uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 - uses: mamba-org/setup-micromamba@v1 with: @@ -26,11 +26,38 @@ jobs: cache-environment: true post-cleanup: 'all' - - name: Run tests + - name: Build and publish Pypi package + shell: micromamba-shell {0} env: - VERSION: ${{ inputs.version }} PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} + run: | + poetry publish --build --username __token__ --password "${PYPI_TOKEN}" + + - name: Build and publish Docker image + shell: micromamba-shell {0} + env: DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} DOCKER_HUB_PUSH_TOKEN: ${{ secrets.DOCKER_HUB_PUSH_TOKEN }} - run: make release + run: | + VERSION=$(poetry version --short) + while [[ $(poetry search copernicusmarine | grep copernicusmarine | awk '{print $2}') != "($VERSION)" ]] + do + echo "Waiting for version $VERSION to be available on Pypi..." + sleep 10 + done + make build-and-publish-dockerhub-image + + - name: Create tag shell: micromamba-shell {0} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git tag v$(poetry version --short) + git push origin --tags + + - name: Create Github release + shell: micromamba-shell {0} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create v$(poetry version --short) diff --git a/.gitignore b/.gitignore index e5245b15..6ef163c1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ copernicusmarine/**/__pycache__/ **/.aliases **/.DS_Store __debug.py +dist/ diff --git a/Makefile b/Makefile index dff1a853..730dd6b3 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,16 @@ run-tests-dependencie-versions: release: SELECTED_ENVIRONMENT_NAME = ${ENVIRONMENT_NAME} release: ${ACTIVATE_ENVIRONMENT} - PYPI_TOKEN=$${PYPI_TOKEN} VERSION=$${VERSION} ./release.sh + ./release.sh + +release-patch: BUMP_TYPE = patch +release-patch: release + +release-minor: BUMP_TYPE = minor +release-minor: release + +release-major: BUMP_TYPE = major +release-major: release build-and-publish-dockerhub-image: docker login --username $${DOCKER_HUB_USERNAME} --password $${DOCKER_HUB_PUSH_TOKEN} diff --git a/conda_environment.yaml b/conda_environment.yaml index 044c7325..ea97d18c 100644 --- a/conda_environment.yaml +++ b/conda_environment.yaml @@ -3,3 +3,4 @@ dependencies: - poetry==1.3.2 - git>=2.30.2,<2.31 - pip >= 23.0.1 + - gh==2.45.0 diff --git a/pyproject.toml b/pyproject.toml index 523727b7..45679b60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "copernicusmarine" -version = "1.0.6" +version = "1.0.7" description = "" authors = ["Copernicus Marine User Support "] readme = "README.md" diff --git a/release.sh b/release.sh index 09f34022..7d79d53b 100755 --- a/release.sh +++ b/release.sh @@ -4,26 +4,17 @@ set -eufo pipefail git switch main git pull -if [ -z `git status --porcelain` ] && [ ! -z "${VERSION}" ] && [ ! -z "${PYPI_TOKEN}" ] ; then +if [ -z `git status --porcelain` ] && [ ! -z "${BUMP_TYPE}" ] ; then RELEASE_BRANCH_NAME="New-copernicusmarine-package-release-${VERSION}" - echo "Starting release..." git checkout -b $RELEASE_BRANCH_NAME - poetry version ${VERSION} - git commit -am "New copernicusmarine package release ${VERSION}" - poetry publish --build --username __token__ --password "${PYPI_TOKEN}" - git switch main - git merge $RELEASE_BRANCH_NAME - rm -rf dist/ - echo "Release ${VERSION} done." + poetry version ${BUMP_TYPE} + VERSION=$(poetry version --short) + RELEASE_TITLE="Copernicus Marine Release ${VERSION}" + git commit -am $RELEASE_TITLE + git push --set-upstream origin $RELEASE_BRANCH_NAME + PR_LINK=$(gh pr create --title $RELEASE_TITLE --body "") + gh pr view $PR_LINK --web else git status - echo "Release ${VERSION} aborted. Clean your repository and specify VERSION and PYPI_TOKEN." + echo "Release aborted. Clean your repository and use make release-[BUMP_TYPE]." fi - -while [[ $(poetry search copernicusmarine | grep copernicusmarine | awk '{print $2}') != "($VERSION)" ]] -do - echo "Waiting for version $VERSION to be available on Pypi..." - sleep 10 -done - -make build-and-publish-dockerhub-image