Skip to content

Commit

Permalink
fix: Release workflow (#67)
Browse files Browse the repository at this point in the history
* set executable for script?

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix
  • Loading branch information
lindnerby authored Oct 16, 2024
1 parent 5327a4d commit 086b362
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 26 deletions.
7 changes: 1 addition & 6 deletions .github/scripts/create_changelog.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/scripts/draft_release.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion .github/scripts/get_release_by_tag.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion .github/scripts/publish_release.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
13 changes: 7 additions & 6 deletions .github/scripts/upload_assets.sh → .github/scripts/upload_artifacts.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ 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
echo "${CURL_RESPONSE}"
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

Expand All @@ -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"
Empty file modified .github/scripts/validate_release_tag.sh
100644 → 100755
Empty file.
24 changes: 13 additions & 11 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 ]
Expand Down

0 comments on commit 086b362

Please sign in to comment.