diff --git a/.github/scripts/create_changelog.sh b/.github/scripts/create_changelog.sh old mode 100644 new mode 100755 index 19b9c067..c5264c1c --- a/.github/scripts/create_changelog.sh +++ b/.github/scripts/create_changelog.sh @@ -1,20 +1,17 @@ #!/usr/bin/env bash - set -o errexit set -E set -o pipefail CURRENT_RELEASE_TAG=$1 -DOCKER_IMAGE_URL=$2 -LAST_RELEASE_TAG=$3 +LAST_RELEASE_TAG=$2 if [ "${LAST_RELEASE_TAG}" == "" ] then LAST_RELEASE_TAG=$(git describe --tags --abbrev=0) fi -GITHUB_URL=https://api.github.com/repos/$CODE_REPOSITORY GITHUB_AUTH_HEADER="Authorization: Bearer $GITHUB_TOKEN" CHANGELOG_FILE="CHANGELOG.md" @@ -29,8 +26,6 @@ done { echo -e "\n**Full changelog**: $GITHUB_URL/compare/$LAST_RELEASE_TAG...$CURRENT_RELEASE_TAG" echo -e "\n" - echo "## Docker image URL" - echo "$DOCKER_IMAGE_URL" } >> $CHANGELOG_FILE cat $CHANGELOG_FILE diff --git a/.github/scripts/draft_release.sh b/.github/scripts/draft_release.sh old mode 100644 new mode 100755 index 81b638b7..06d3ef0f --- a/.github/scripts/draft_release.sh +++ b/.github/scripts/draft_release.sh @@ -7,8 +7,8 @@ set -o pipefail RELEASE_TAG=$1 -GITHUB_URL=https://api.github.com/repos/${CODE_REPOSITORY} GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" + CHANGELOG_FILE=$(cat CHANGELOG.md) JSON_PAYLOAD=$(jq -n \ diff --git a/.github/scripts/get_release_by_tag.sh b/.github/scripts/get_release_by_tag.sh old mode 100644 new mode 100755 index 00f680dc..732cfc72 --- a/.github/scripts/get_release_by_tag.sh +++ b/.github/scripts/get_release_by_tag.sh @@ -6,7 +6,6 @@ set -o pipefail RELEASE_TAG=$1 GITHUB_TOKEN=$2 -GITHUB_URL=https://api.github.com/repos/$CODE_REPOSITORY GITHUB_AUTH_HEADER="Authorization: Bearer $GITHUB_TOKEN" curl -L \ diff --git a/.github/scripts/publish_release.sh b/.github/scripts/publish_release.sh old mode 100644 new mode 100755 index d4c0d38b..cb638536 --- a/.github/scripts/publish_release.sh +++ b/.github/scripts/publish_release.sh @@ -7,7 +7,6 @@ set -o pipefail RELEASE_ID=$1 -GITHUB_URL=https://api.github.com/repos/${CODE_REPOSITORY} GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" CURL_RESPONSE=$(curl -L \ diff --git a/.github/scripts/upload_assets.sh b/.github/scripts/upload_artifacts.sh old mode 100644 new mode 100755 similarity index 75% rename from .github/scripts/upload_assets.sh rename to .github/scripts/upload_artifacts.sh index a26f6a7c..e8304eea --- a/.github/scripts/upload_assets.sh +++ b/.github/scripts/upload_artifacts.sh @@ -25,13 +25,13 @@ uploadFile() { fi } -echo "PULL_BASE_REF= ${PULL_BASE_REF}" +RELEASE_TAG=$1 echo "Fetching releases" CURL_RESPONSE=$(curl -w "%{http_code}" -sL \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GITHUB_TOKEN"\ - https://api.github.com/repos/kyma-project/modulectl/releases) + "$GITHUB_URL"/releases) JSON_RESPONSE=$(sed '$ d' <<< "${CURL_RESPONSE}") HTTP_CODE=$(tail -n1 <<< "${CURL_RESPONSE}") if [[ "${HTTP_CODE}" != "200" ]]; then @@ -39,13 +39,13 @@ if [[ "${HTTP_CODE}" != "200" ]]; then exit 1 fi -echo "Finding release id for: ${PULL_BASE_REF}" -RELEASE_ID=$(jq <<< "${JSON_RESPONSE}" --arg tag "${PULL_BASE_REF}" '.[] | select(.tag_name == $ARGS.named.tag) | .id') +echo "Finding release id for: ${RELEASE_TAG}" +RELEASE_ID=$(jq <<< "${JSON_RESPONSE}" --arg tag "${RELEASE_TAG}" '.[] | select(.tag_name == $ARGS.named.tag) | .id') echo "Got '${RELEASE_ID}' release id" if [ -z "${RELEASE_ID}" ] then - echo "No release with tag = ${PULL_BASE_REF}" + echo "No release with tag = ${RELEASE_TAG}" exit 1 fi @@ -55,4 +55,5 @@ UPLOAD_URL="https://uploads.github.com/repos/kyma-project/modulectl/releases/${R echo "$UPLOAD_URL" pwd ls -la -uploadFile "modulectl-linux" "${UPLOAD_URL}?name=modulectl-linux" +echo "modulectl-linux" "${UPLOAD_URL}?name=modulectl-linux" +#uploadFile "modulectl-linux" "${UPLOAD_URL}?name=modulectl-linux" diff --git a/.github/scripts/validate_release_tag.sh b/.github/scripts/validate_release_tag.sh old mode 100644 new mode 100755 diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 1a9633fa..e0550c1c 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -1,9 +1,12 @@ name: "Create release" +env: + GITHUB_URL: https://api.github.com/repos/kyma-project/modulectl + on: workflow_dispatch: inputs: - version: + tag: description: "Release version" default: "" required: true @@ -21,9 +24,9 @@ jobs: with: fetch-depth: 0 - name: Validate the release tag - run: ./.github/scripts/validate_release_tag.sh ${{ github.event.inputs.version }} + run: ./.github/scripts/validate_release_tag.sh ${{ github.event.inputs.tag }} - name: Check if release exists - run: ./.github/scripts/get_release_by_tag.sh ${{ github.event.inputs.version }} ${{ secrets.GITHUB_TOKEN }} + run: ./.github/scripts/get_release_by_tag.sh ${{ github.event.inputs.tag }} ${{ secrets.GITHUB_TOKEN }} draft-release: runs-on: ubuntu-latest needs: validate-release @@ -35,23 +38,23 @@ jobs: - name: Create changelog env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./.github/scripts/create_changelog.sh ${{ github.event.inputs.version }} ${{ env.IMAGE_REPO }}:${{ github.event.inputs.version }} ${{ github.event.inputs.since }} + run: ./.github/scripts/create_changelog.sh ${{ github.event.inputs.tag }} ${{ github.event.inputs.since }} - name: Draft release id: draft-release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - RELEASE_ID=$(./.github/scripts/draft_release.sh ${{ github.event.inputs.version }}) + RELEASE_ID=$(./.github/scripts/draft_release.sh ${{ github.event.inputs.tag }}) echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT - name: Create tag run: | - git tag ${{ github.event.inputs.version }} - git push origin ${{ github.event.inputs.version }} --tags + git tag ${{ github.event.inputs.tag }} + git push origin ${{ github.event.inputs.tag }} --tags outputs: release_id: ${{ steps.draft-release.outputs.release_id }} artifacts: runs-on: ubuntu-latest - needs: validate-release + needs: draft-release steps: - name: Checkout uses: actions/checkout@v4 @@ -61,12 +64,11 @@ jobs: go-version-file: 'go.mod' cache-dependency-path: 'go.sum' - name: "Run 'make build' with version" - run: make build VERSION=${{ inputs.version }} + run: make build VERSION=${{ github.event.inputs.tag }} - name: Add binaries to draft env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PULL_BASE_REF: ${{ github.event.inputs.version }} - run: ./.github/scripts/upload_assets.sh + run: ./.github/scripts/upload_artifacts.sh ${{ github.event.inputs.tag }} publish-release: runs-on: ubuntu-latest needs: [ validate-release, draft-release, artifacts ]