diff --git a/.github/scripts/PublishDocker.bash b/.github/scripts/PublishDocker.bash new file mode 100644 index 0000000..9ad13f0 --- /dev/null +++ b/.github/scripts/PublishDocker.bash @@ -0,0 +1,51 @@ +#!/bin/bash + +# A script to decide what version to upload + +# Set current repository variable +REPOSITORY=paveloom-d/dev + +# Get last published version +LAST_VERSION=$(curl --silent "https://api.github.com/repos/$REPOSITORY/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + +# Check if there is some tag +if [ ! -z "$LAST_VERSION" ]; then + + # Get current tag + CURRENT_TAG=$(echo ${GITHUB_REF#refs/*/}) + + # Print info + echo -e "\n\e[1m\033[36mLast version: $LAST_VERSION\033[0m" + echo -e "\e[1m\033[36mCurrent tag: $CURRENT_TAG\033[0m\n" + + # Check if the tag is a semantic version + if echo "$CURRENT_TAG" | grep -q "v[0-9]*.[0-9]*.[0-9]*"; then + + # Print information + echo -e "\e[1m\033[36mCurrent tag is a semantic version. Tagged image will be published.\033[0m\n" + + # Set environment variable + echo ::set-env name=RELEASE_VERSION::$(echo ${CURRENT_TAG} | sed 's/v//') + + # Publish tagged image + echo ::set-env name=PUBLISH_RELEASE_VERSION::$(echo true) + + else + + # Print information + echo -e "\e[1m\033[36mCurrent tag is not a semantic version. Tagged image will not be published.\033[0m\n" + + # Don't publish tagged image + echo ::set-env name=PUBLISH_RELEASE_VERSION::$(echo false) + + fi + +else + + # Print information + echo -e "\n\e[1m\033[36mNo release has been found, tagged version will not be published.\033[0m\n" + + # Don't publish tagged image + echo ::set-env name=PUBLISH_RELEASE_VERSION::$(echo false) + +fi \ No newline at end of file diff --git a/.github/scripts/VersionCheck.bash b/.github/scripts/VersionCheck.bash index 39982e7..6954089 100644 --- a/.github/scripts/VersionCheck.bash +++ b/.github/scripts/VersionCheck.bash @@ -56,7 +56,7 @@ get_latest_release() { # and Semantic Versioning was respected) LAST_VERSION=$(get_latest_release "paveloom-d/dev") -# Check if there is a some tag +# Check if there is some tag if [ ! -z "$LAST_VERSION" ]; then # Escape last version diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index d72069a..2621b4c 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -13,13 +13,24 @@ jobs: steps: - uses: actions/checkout@master - name: Get release version - id: get_version - run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10}) - - name: Publish to Registry + run: bash .github/scripts/PublishDocker.bash + + - name: Publish to Registry (with tagged image) + if: ${{ env.PUBLISH_RELEASE_VERSION == 'true' }} + uses: elgohr/Publish-Docker-Github-Action@master + with: + name: paveloom-d/dev/dev + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + registry: docker.pkg.github.com + tags: "latest,${{ env.RELEASE_VERSION }}" + + - name: Publish to Registry (without tagged image) + if: ${{ env.PUBLISH_RELEASE_VERSION == 'false' }} uses: elgohr/Publish-Docker-Github-Action@master with: name: paveloom-d/dev/dev username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} registry: docker.pkg.github.com - tags: "latest,${{ env.RELEASE_VERSION }}" \ No newline at end of file + tags: "latest" \ No newline at end of file