diff --git a/.github/workflows/publish_hortacloud_deployment.yml b/.github/workflows/publish_hortacloud_deployment.yml new file mode 100644 index 0000000..400b490 --- /dev/null +++ b/.github/workflows/publish_hortacloud_deployment.yml @@ -0,0 +1,78 @@ +name: Publish hortacloud_deployment +on: + push: + branches: + - main + paths: + - hortacloud-deployment/** +env: + DOCKERFILE_DIR: ./hortacloud-deployment + DOCKERFILE_PATH: ./hortacloud-deployment/Dockerfile +jobs: + bump_version: + name: Bump version + runs-on: ubuntu-latest + outputs: + new_version: ${{ steps.update_dockerfile.outputs.new_version }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: ${{ inputs.default_branch }} + fetch-depth: 0 + token: ${{ secrets.SERVICE_TOKEN }} + - name: Check changes and bump version in file + id: update_dockerfile + run: | + docker_file=${{ env.DOCKERFILE_PATH }} + first_line=$(head -n 1 $docker_file) + old_version=${first_line:3} + most_recent_commit=$(git log --oneline | head -1) + echo "Most recent commit message first line:" + echo " ${most_recent_commit}" + if [[ "${most_recent_commit^^}" == *"BREAKING CHANGE"* ]]; then + echo "Major version bump" + new_version=$(IFS=. read -r a b c<<<"$old_version";echo "$((a+1)).0.0") + elif [[ "${most_recent_commit^^}" == *"FEAT"* ]]; then + echo "Minor version bump" + new_version=$(IFS=. read -r a b c<<<"$old_version";echo "$a.$((b+1)).0") + else + echo "Patch version bump" + new_version=$(IFS=. read -r a b c<<<"$old_version";echo "$a.$b.$((c+1))") + fi + echo "Saving new_version to GITHUB_OUTPUT" + echo "new_version=${new_version}" >> "$GITHUB_OUTPUT" + echo "Updating version number in ${docker_file}" + new_docker_file_line="# v${new_version}" + sed -i "1s/.*/$new_docker_file_line/" ${docker_file} + - name: Commit and Push version bump + uses: EndBug/add-and-commit@v9 + with: + default_author: github_actions + message: "ci: version bump [skip actions]" + add: ${{ env.DOCKERFILE_PATH }} + publish: + runs-on: ubuntu-latest + needs: bump_version + steps: + - uses: actions/checkout@v3 + - name: Pull latest changes + run: git pull origin main + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Github Packages + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build image and push to GitHub Container Registry + uses: docker/build-push-action@v3 + with: + # relative path to the place where source code with Dockerfile is located + context: ${{ env.DOCKERFILE_DIR }} + push: true + tags: | + ghcr.io/allenneuraldynamics/hortacloud-deployment:${{ needs.bump_version.outputs.new_version }} + ghcr.io/allenneuraldynamics/hortacloud-deployment:latest diff --git a/.github/workflows/tag_and_publish.yml b/.github/workflows/tag_and_publish.yml deleted file mode 100644 index 2aad22a..0000000 --- a/.github/workflows/tag_and_publish.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Tag and publish -on: - push: - branches: - - main - paths: - - hortacloud-deployment/** -jobs: - tag: - uses: AllenNeuralDynamics/aind-github-actions/.github/workflows/tag.yml@main - secrets: - SERVICE_TOKEN: ${{ secrets.SERVICE_TOKEN }} - - publish: - runs-on: ubuntu-latest - needs: tag - steps: - - uses: actions/checkout@v3 - - name: Pull latest changes - run: git pull origin main - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v2 - - name: Login to Github Packages - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build image and push to GitHub Container Registry - uses: docker/build-push-action@v3 - with: - # relative path to the place where source code with Dockerfile is located - context: ./horta-deployment - push: true - tags: | - ghcr.io/allenneuraldynamics/hortacloud-deployment:${{ needs.tag.outputs.new_version }} - ghcr.io/allenneuraldynamics/hortacloud-deployment:latest diff --git a/hortacloud-deployment/Dockerfile b/hortacloud-deployment/Dockerfile index 6001fee..cc560e1 100644 --- a/hortacloud-deployment/Dockerfile +++ b/hortacloud-deployment/Dockerfile @@ -1,3 +1,4 @@ +# v0.0.0 from node:16 RUN apt-get update && \