Skip to content

Commit

Permalink
retry with github script and cover manual install usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubramanianaks committed Jul 6, 2023
1 parent fc0616c commit afad0a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/integration-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Get Draft Cli version
uses: actions/github-script@v6
id: get_draft_version
with:
result-encoding: string
retries : 3
script: |
const tag_url = context.payload.repository.releases_url.replace('{/id}', '/latest');
const response = await github.request(tag_url);
return response.data.tag_name;
- name: Run Install Script
shell: bash
run: ./scripts/install.sh
env:
DRAFT_CLI_VERSION: ${{ steps.get_draft_version.outputs.result }}
- name: Validate Command is Installed
shell: bash
run: |
Expand Down
27 changes: 6 additions & 21 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,32 +112,17 @@ download_draft_cli_stable_version(){
FILENAME="draft-$OS-$ARCH"
fi
log INFO "Starting Draft CLI Download for $FILENAME"
get_draft_cli_version
DRAFTCLIURL="https://github.com/Azure/draft/releases/download/$DRAFTCLIVERSION/$FILENAME"
# For Github actions integration-install tests DRAFT_CLI_VERSION will be set an env variable i.e., check integration-install.yml, but when the user runs the script locally, it will be empty.
if [ -z "${DRAFT_CLI_VERSION}" ]; then
DRAFT_CLI_VERSION=$(curl -L -s https://api.github.com/repos/Azure/draft/releases/latest | jq -r '.tag_name')
fi
log INFO "Draft CLI Version $DRAFT_CLI_VERSION"
DRAFTCLIURL="https://github.com/Azure/draft/releases/download/$DRAFT_CLI_VERSION/$FILENAME"
curl -o /tmp/draftcli -fLO $DRAFTCLIURL
chmod +x /tmp/draftcli
log INFO "Finished Draft CLI download complete."
}

get_draft_cli_version() {
retry=0
log INFO "Getting Draft CLI version"
while [ -z "${DRAFTCLIVERSION}" ];
do
DRAFTCLIVERSION=$(curl -L -s https://api.github.com/repos/Azure/draft/releases/latest | jq -r '.tag_name')
if [ -z "${DRAFTCLIVERSION}" ]; then
log INFO "Unable to get Draft CLI version"
retry=$((retry++))
if [ $retry -eq 5 ]; then
log ERROR "Unable to get Draft CLI version"
exit 1
fi
sleep 5
fi
done
log INFO "Draft CLI Version $DRAFTCLIVERSION"
}

file_issue_prompt() {
echo "If you wish us to support your platform, please file an issue"
echo "https://github.com/Azure/draft/issues/new/choose"
Expand Down

0 comments on commit afad0a2

Please sign in to comment.