Skip to content

Commit

Permalink
Fix workflow issues (#10)
Browse files Browse the repository at this point in the history
* Using semver check for latest release

Signed-off-by: shivam <[email protected]>

* Setting PRERELEASE and RUNTIME_VERSION

Signed-off-by: shivam <[email protected]>

* Adding workflow_dispatch and updating release

Signed-off-by: shivam <[email protected]>

* Updating requirements.txt

Signed-off-by: shivam <[email protected]>
  • Loading branch information
shivamkm07 authored Jun 29, 2022
1 parent 45a9846 commit e0134bf
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 46 deletions.
27 changes: 19 additions & 8 deletions .github/scripts/build_daprbundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
from http.client import OK
import subprocess
import tarfile
from tkinter import Variable
import zipfile
import requests
import json
import os
import sys
import shutil
import semver
import stat


Expand Down Expand Up @@ -51,20 +53,29 @@

global runtime_os,runtime_arch,runtime_ver,dashboard_ver,cli_ver

# Returns the latest release/tag of given repo(e.g. `dapr`)

# Returns latest release/pre-release version of the given repo from GitHub (e.g. `dapr`)
def getLatestRelease(repo):
daprReleaseUrl = "https://api.github.com/repos/" + GITHUB_ORG + "/" + repo + "/releases"
print(daprReleaseUrl)
latest_release = ""
resp = requests.get(daprReleaseUrl)
if resp.status_code != requests.codes.ok:
print(f"Error pulling latest release of {repo}")
resp.raise_for_status()
sys.exit(1)
data = json.loads(resp.text)
version = data[0]['tag_name'].lstrip("v")
print(version)
return version
versions = []
for release in data:
if not release["draft"]:
versions.append(release["tag_name"].lstrip("v"))
if len(versions) == 0:
print(f"No releases found for {repo}")
sys.exit(1)
latest_release = versions[0]
for version in versions:
if semver.compare(version,latest_release) > 0:
latest_release = version
return latest_release

# Returns the complete filename of the archived binary(e.g. `daprd_linux_amd64.tar.gz`)
def binaryFileName(fileBase):
Expand Down Expand Up @@ -186,11 +197,11 @@ def parseArguments():
cli_ver = str(args["cli_ver"])
ARCHIVE_DIR = str(args["archive_dir"])

if runtime_ver == "latest":
if runtime_ver == "latest" or runtime_ver == "":
runtime_ver = getLatestRelease(GITHUB_DAPR_REPO)
if dashboard_ver == "latest":
if dashboard_ver == "latest" or dashboard_ver == "":
dashboard_ver = getLatestRelease(GITHUB_DASHBOARD_REPO)
if cli_ver == "latest":
if cli_ver == "latest" or cli_ver == "":
cli_ver = getLatestRelease(GITHUB_CLI_REPO)

# Deletes a file if exists
Expand Down
5 changes: 5 additions & 0 deletions .github/scripts/get_release_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@
with open(os.getenv("GITHUB_ENV"), "a") as githubEnv:
if gitRef is None or not gitRef.startswith(tagRefPrefix):
githubEnv.write("REL_VERSION=edge\n")
githubEnv.write("RUNTIME_VERSION=latest\n")
print ("This is daily build from {}...".format(gitRef))
sys.exit(0)

releaseVersion = gitRef[len(tagRefPrefix):]

if gitRef.find("-rc.") > 0:
print ("Release Candidate build from {}...".format(gitRef))
githubEnv.write("PRERELEASE=true\n")
else:
# Set LATEST_RELEASE to true
githubEnv.write("LATEST_RELEASE=true\n")
githubEnv.write("PRERELEASE=false\n")
print ("Release build from {}...".format(gitRef))

githubEnv.write("REL_VERSION={}\n".format(releaseVersion))
runtimeVersion = releaseVersion.split("+")[0]
githubEnv.write("RUNTIME_VERSION={}\n".format(runtimeVersion))
103 changes: 66 additions & 37 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ on:
- release-*
tags:
- v*
workflow_dispatch:
inputs:
runtime_ver:
description: "Dapr Runtime Version"
required: false
default: "latest"
type: string
cli_ver:
description: "Dapr CLI Version"
required: false
default: "latest"
type: string
dashboard_ver:
description: "Dapr Dashboard Version"
required: false
default: "latest"
type: string

pull_request:
branches:
- main
Expand Down Expand Up @@ -66,18 +84,19 @@ jobs:
- name: Parse release version and set REL_VERSION
run: python ./.github/scripts/get_release_version.py

- name: Check REL_VERSION
if: matrix.target_os == 'linux' && matrix.target_arch == 'amd64'
- name: Check env variables
run: |
echo RELEASE VERSION: ${{env.REL_VERSION}}
echo RUNTIME VERSION: ${{env.RUNTIME_VERSION}}
echo GITHUB_EVENT_NAME: ${GITHUB_EVENT_NAME}
- name: Create and Archive bundle
run: python ./.github/scripts/build_daprbundle.py --runtime_os=${{matrix.target_os}} --runtime_arch=${{matrix.target_arch}} --archive_dir=${{env.ARCHIVE_DIR}}
- name: Create and Archive bundle in workflow_dispatch
if: github.event_name == 'workflow_dispatch'
run: python ./.github/scripts/build_daprbundle.py --runtime_os=${{matrix.target_os}} --runtime_arch=${{matrix.target_arch}} --archive_dir=${{env.ARCHIVE_DIR}} --runtime_ver=${{inputs.runtime_ver}} --cli_ver=${{inputs.cli_ver}} --dashboard_ver=${{inputs.dashboard_ver}}

- name: Create release_version.txt
if: matrix.target_arch == 'amd64' && matrix.target_os == 'linux'
run: |
[ ! -z "${{ env.REL_VERSION }}" ] && echo "${{ env.REL_VERSION }}" > "${{ env.ARCHIVE_DIR }}/release_version.txt"
- name: Create and Archive bundle without workflow_dispatch
if: github.event_name != 'workflow_dispatch'
run: python ./.github/scripts/build_daprbundle.py --runtime_os=${{matrix.target_os}} --runtime_arch=${{matrix.target_arch}} --archive_dir=${{env.ARCHIVE_DIR}} --runtime_ver=${{env.RUNTIME_VERSION}}

- name: Upload artifacts
uses: actions/upload-artifact@master
Expand All @@ -92,45 +111,55 @@ jobs:
ARTIFACT_DIR: ./release
runs-on: ubuntu-latest
steps:

- name: Checkout code into current directory
uses: actions/checkout@v2

- name: Parse release version and set REL_VERSION
run: python ./.github/scripts/get_release_version.py

- name: download artifacts
uses: actions/download-artifact@master
with:
name: bundle_drop
path: ${{env.ARTIFACT_DIR}}

- name: Set Release Version
run: |
REL_VERSION_FILE="${{ env.ARTIFACT_DIR }}/release_version.txt"
REL_VER=`cat ${REL_VERSION_FILE}`
echo "REL_VERSION=${REL_VER}" >> $GITHUB_ENV
rm -f ${REL_VERSION_FILE}

- name: generate checksum files
run: cd ${ARTIFACT_DIR} && for i in *; do sha256sum -b $i > "$i.sha256"; done && cd -

- name: lists artifacts
run: ls -l ${{ env.ARTIFACT_DIR }}

- name: publish binaries to github
if: startswith(github.ref, 'refs/tags/v')
run: |
echo "installing github-release-cli..."
sudo npm install --silent --no-progress -g [email protected]
# Get the list of files
RELEASE_ARTIFACT=(${ARTIFACT_DIR}/*)
# Parse repository to get owner and repo names
OWNER_NAME="${GITHUB_REPOSITORY%%/*}"
REPO_NAME="${GITHUB_REPOSITORY#*/}"
export GITHUB_TOKEN=${{ secrets.DAPR_BOT_TOKEN }}
echo "Uploading Dapr Installer-Bundle to GitHub Release"
github-release upload \
--owner $OWNER_NAME --repo $REPO_NAME \
--tag "v${REL_VERSION}" \
--name "Dapr Installer-Bundle v${REL_VERSION}" \
--prerelease true \
${RELEASE_ARTIFACT[*]}

- name: Upload release using ncipollo/release-action
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.ARTIFACT_DIR }}/*"
token: ${{ secrets.DAPR_BOT_TOKEN }}
tag: "v${{ env.REL_VERSION }}"
name: "Dapr Installer-Bundle v${{ env.REL_VERSION }}"
prerelease: ${{ env.PRERELEASE }}
allowUpdates: true

# - name: publish binaries to github
# if: startswith(github.ref, 'refs/tags/v')
# run: |
# echo "installing github-release-cli..."
# sudo npm install --silent --no-progress -g [email protected]
# # Get the list of files
# RELEASE_ARTIFACT=(${ARTIFACT_DIR}/*)
# # Parse repository to get owner and repo names

# OWNER_NAME="${GITHUB_REPOSITORY%%/*}"
# REPO_NAME="${GITHUB_REPOSITORY#*/}"

# export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}

# echo "Uploading Dapr Installer-Bundle to GitHub Release"
# github-release upload \
# --owner $OWNER_NAME --repo $REPO_NAME \
# --tag "v${REL_VERSION}" \
# --name "Dapr Installer-Bundle v${REL_VERSION}" \
# --prerelease true \
# ${RELEASE_ARTIFACT[*]}


3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
requests==2.24.0
requests==2.24.0
semver==2.13.0

0 comments on commit e0134bf

Please sign in to comment.