Skip to content

Commit

Permalink
Rework workflow and release process (#7)
Browse files Browse the repository at this point in the history
Co-authored-by: mbertin <[email protected]>
  • Loading branch information
nitreb and mbertin committed Mar 25, 2024
1 parent 41da65b commit 310d17e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 30 deletions.
45 changes: 36 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ copernicusmarine/**/__pycache__/
**/.aliases
**/.DS_Store
__debug.py
dist/
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
BUMP_TYPE=${BUMP_TYPE} ./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}
Expand Down
1 change: 1 addition & 0 deletions conda_environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dependencies:
- poetry==1.3.2
- git>=2.30.2,<2.31
- pip >= 23.0.1
- gh==2.45.0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "copernicusmarine"
version = "1.0.6"
version = "1.0.7"
description = ""
authors = ["Copernicus Marine User Support <[email protected]>"]
readme = "README.md"
Expand Down
29 changes: 10 additions & 19 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,17 @@ set -eufo pipefail

git switch main
git pull
if [ -z `git status --porcelain` ] && [ ! -z "${VERSION}" ] && [ ! -z "${PYPI_TOKEN}" ] ; then
RELEASE_BRANCH_NAME="New-copernicusmarine-package-release-${VERSION}"
echo "Starting release..."
if [ -z `git status --porcelain` ] && [ ! -z "${BUMP_TYPE}" ] ; then
RELEASE_BRANCH_NAME="New-copernicusmarine-package-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

0 comments on commit 310d17e

Please sign in to comment.