Skip to content

Commit 636a948

Browse files
committed
[build] Use ODO binary from nightly builds
Since the [ODO project](https://github.com/redhat-developer/odo) has stoped producing new releases for ODO binary, the [nightly builds](https://odo.dev/docs/overview/installation/#nightly-builds) became the source of most recent and up-to-date ODO binary version. Fixes: redhat-developer#4183 Signed-off-by: Victor Rubezhny <[email protected]>
1 parent 3f586f9 commit 636a948

File tree

1 file changed

+103
-23
lines changed

1 file changed

+103
-23
lines changed

.github/workflows/check-odo.yml

Lines changed: 103 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,122 @@ on:
44
schedule:
55
- cron: "0 8 * * *"
66
workflow_dispatch:
7+
env:
8+
TOOL_REPO: redhat-developer/odo
9+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
710
jobs:
8-
check-odo-repo:
11+
check-odo:
912
runs-on: ubuntu-latest
10-
env:
11-
TOOL_REPO: redhat-developer/odo
12-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
outputs:
14+
cache-hit: ${{ steps.cache-last-commit.outputs.cache-hit }}
15+
last-commit-id: ${{ steps.repo-last-commit-info.outputs.repo-last-commit-id }}
16+
last-release-tag: ${{ steps.repo-last-commit-info.outputs.repo-last-release-tag }}
17+
last-release-version: ${{ steps.repo-last-commit-info.outputs.repo-last-release-version }}
18+
nightly-build-version: ${{ steps.repo-last-commit-info.outputs.repo-nightly-build-version }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
repository: '${{ env.TOOL_REPO}}'
23+
fetch-depth: 2
24+
fetch-tags: false
25+
path: redhat-developer-odo-repository
26+
- name: Get Last Commit Info
27+
id: repo-last-commit-info
28+
run: |
29+
pushd redhat-developer-odo-repository
30+
31+
# Last Commit ID (short or abbreviated to 9 characters version)
32+
lastCommitId="$(git describe --no-match --always --abbrev=9 --dirty --broken 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)"
33+
echo "repo-last-commit-id=$lastCommitId" >> $GITHUB_OUTPUT
34+
35+
# Last Release Tag and Version
36+
lastReleaseTag=$(gh release --repo ${{ env.TOOL_REPO }} view --json tagName | jq -r .tagName)
37+
lastReleaseVersion="$(echo $lastReleaseTag | sed 's|v||')"
38+
echo "repo-last-release-tag=$lastReleaseTag" >> $GITHUB_OUTPUT
39+
echo "repo-last-release-version=$lastReleaseVersion" >> $GITHUB_OUTPUT
40+
41+
# Nightly Build Version
42+
echo "repo-nightly-build-version=$lastReleaseVersion (${lastCommitId}-nightly)" >> $GITHUB_OUTPUT
43+
44+
# Update cache
45+
echo "$lastCommitId" >> ../lastCommit
46+
47+
popd
48+
- name: Check New Changes
49+
id: cache-last-commit
50+
uses: actions/cache@v4
51+
with:
52+
path: lastCommit
53+
key: lastCommit-${{ hashFiles('lastCommit') }}
54+
55+
check-nightly-build:
56+
runs-on: ubuntu-latest
57+
outputs:
58+
nightly-build-exists: ${{ steps.check-nightly-build-exists.outputs.nightly-build-exists }}
59+
needs: check-odo
60+
if: ${{ needs.check-odo.outputs.cache-hit != 'true' || github.event_name != 'schedule' }}
61+
steps:
62+
- name: Check if a Nightly Build exists for the last commit id
63+
id: check-nightly-build-exists
64+
run: echo nightly-build-exists=`curl -s "https://s3.eu-de.cloud-object-storage.appdomain.cloud/odo-nightly-builds/odo-linux-arm64-${{ needs.check-odo.outputs.last-commit-id }}.tar.gz.sha256" | grep -E "^[A-Za-z0-9]+$" | wc -w` >> $GITHUB_OUTPUT
65+
66+
check-pr:
67+
runs-on: ubuntu-latest
68+
outputs:
69+
pr-exists: ${{ steps.check-pr-exists.outputs.pr-exists }}
70+
needs: check-odo
71+
if: ${{ needs.check-odo.outputs.cache-hit != 'true' || github.event_name != 'schedule' }}
72+
steps:
73+
- name: Check if the update PR already exists
74+
id: check-pr-exists
75+
run: echo pr-exists=$(gh pr --repo ${{ github.repository }} list --state all --search "update odo cli to ${{ needs.check-odo.outputs.last-release-version }} (${{ needs.check-odo.outputs.last-commit-id }}-nightly) in:title" --json url | jq length) >> $GITHUB_OUTPUT
76+
77+
update-odo:
78+
runs-on: ubuntu-latest
79+
needs: [check-odo, check-nightly-build, check-pr]
80+
if: ${{ (needs.check-odo.outputs.cache-hit != 'true' || github.event_name != 'schedule') && needs.check-nightly-build.outputs.nightly-build-exists == 1 && needs.check-pr.outputs.pr-exists == 0 }}
1381
steps:
1482
- name: Check Out Code
1583
uses: actions/checkout@v4
16-
- name: Get latest ODO version
17-
run: |
18-
echo "REPO_ODO_VERSION=$(cat src/tools.json | jq -r .odo.version)" >> $GITHUB_ENV
19-
LATEST_TOOL_RELEASE_RESP=$(gh release --repo ${{ env.TOOL_REPO }} view --json tagName,url)
20-
echo "LATEST_TOOL_RELEASE=$(echo ${LATEST_TOOL_RELEASE_RESP} | jq -r .tagName | sed 's|v||')" >> $GITHUB_ENV
21-
echo "LATEST_TOOL_URL=$(echo ${LATEST_TOOL_RELEASE_RESP} | jq -r .url)" >> $GITHUB_ENV
22-
- name: Find existing PR for ODO version
23-
run: |
24-
echo PR_EXISTS=$(gh pr --repo ${{ github.repository }} list --state all --search "update odo ${{env.LATEST_TOOL_RELEASE}} in:title" --json url | jq length) >> $GITHUB_ENV
2584
- name: Update src/tools.json with latest odo version
26-
if: ${{ (env.LATEST_TOOL_RELEASE != '') && (env.LATEST_TOOL_RELEASE != env.REPO_ODO_VERSION) && (env.PR_EXISTS == 0) }}
2785
run: |
28-
jq --indent 4 '.odo.version = "${{ env.LATEST_TOOL_RELEASE }}"' src/tools.json | jq --indent 4 '.odo.versionRange = "^${{ env.LATEST_TOOL_RELEASE }}"' | jq --indent 4 '.odo.versionRangeLabel = "version >= ${{ env.LATEST_TOOL_RELEASE }}"' > src/tools.json.new
86+
jq --indent 4 '.odo.description = "ODO CLI tool"' src/tools.json \
87+
| jq --indent 4 '.odo.vendor = "Red Hat Developer"' \
88+
| jq --indent 4 '.odo.name = "odo"' \
89+
| jq --indent 4 '.odo.version = "${{ needs.check-odo.outputs.last-release-version }}"' \
90+
| jq --indent 4 '.odo.versionRange = "^${{ needs.check-odo.outputs.last-release-version }}"' \
91+
| jq --indent 4 '.odo.versionRangeLabel = "version >= ${{ needs.check-odo.outputs.last-release-version }}"' > src/tools.json.new
2992
mv src/tools.json.new src/tools.json
3093
for platform in win32 darwin darwin-arm64 linux linux-arm64; do
31-
old_url=`jq -r .odo.platform.${platform}.url src/tools.json`
32-
new_url=`echo ${old_url} | sed "s|${{ env.REPO_ODO_VERSION }}|${{ env.LATEST_TOOL_RELEASE }}|"`
94+
pltfrm="$platform"
95+
ext=".tar.gz"
96+
exeExt=""
97+
if [[ "$platform" == "win"* ]]; then
98+
pltfrm="windows"
99+
ext=".zip"
100+
exeExt=".exe"
101+
fi
102+
arch="-amd64"
103+
if [[ $platform == *"-a"* ]]; then
104+
arch="" # already in platform string
105+
fi
106+
old_url=`jq -r ".odo.platform[\"${platform}\"].url" src/tools.json`
107+
new_url="https://s3.eu-de.cloud-object-storage.appdomain.cloud/odo-nightly-builds/odo-${pltfrm}${arch}-${{ needs.check-odo.outputs.last-commit-id }}${ext}"
33108
checksum=`curl -s ${new_url}.sha256`
34-
jq --indent 4 ".odo.platform.${platform}.url = \"${new_url}\"" src/tools.json | jq --indent 4 ".odo.platform.${platform}.sha256sum = \"${checksum}\"" > src/tools.json.new
109+
dlFileName="odo-${pltfrm}${arch}${ext}"
110+
cmdFileName="odo${exeExt}"
111+
jq --indent 4 ".odo.platform[\"${platform}\"].url = \"${new_url}\"" src/tools.json \
112+
| jq --indent 4 ".odo.platform[\"${platform}\"].sha256sum = \"${checksum}\"" \
113+
| jq --indent 4 ".odo.platform[\"${platform}\"].dlFileName = \"${dlFileName}\"" \
114+
| jq --indent 4 ".odo.platform[\"${platform}\"].cmdFileName = \"${cmdFileName}\"" > src/tools.json.new > src/tools.json.new
35115
mv src/tools.json.new src/tools.json
36116
done
37117
- name: Create pull request
38-
if: ${{ (env.LATEST_TOOL_RELEASE != '') && (env.LATEST_TOOL_RELEASE != env.REPO_ODO_VERSION) && (env.PR_EXISTS == 0) }}
39118
run: |
40119
git config --global user.email "[email protected]"
41120
git config --global user.name "openshifttools-bot"
42-
git checkout -b "odo-${{ env.LATEST_TOOL_RELEASE }}"
43-
git commit -am "Update odo to ${{ env.LATEST_TOOL_RELEASE }}"
44-
git push origin "odo-${{ env.LATEST_TOOL_RELEASE }}"
45-
gh pr create --title "Update odo to ${{ env.LATEST_TOOL_RELEASE }}" --body "See ${{ env.LATEST_TOOL_URL }}"
121+
git checkout -b "bump-odo-${{ needs.check-odo.outputs.last-release-version }}-${{ needs.check-odo.outputs.last-commit-id }}"
122+
git commit -am "Update ODO CLI to ${{ needs.check-odo.outputs.nightly-build-version }}"
123+
git push -f origin "bump-odo-${{ needs.check-odo.outputs.last-release-version }}-${{ needs.check-odo.outputs.last-commit-id }}"
124+
gh pr create --title "Update ODO CLI to ${{ needs.check-odo.outputs.nightly-build-version }}" \
125+
--body "See the commit history between release ${{needs.check-odo.outputs.last-release-version}} and the latest nightly version ${{ needs.check-odo.outputs.nightly-build-version }} at: https://github.com/redhat-developer/odo/compare/${{needs.check-odo.outputs.last-release-tag}}...${{ needs.check-odo.outputs.last-commit-id }}"

0 commit comments

Comments
 (0)