|
5 | 5 | - cron: "0 8 * * *" |
6 | 6 | workflow_dispatch: |
7 | 7 | jobs: |
8 | | - check-odo-repo: |
| 8 | + should-check-odo: |
9 | 9 | runs-on: ubuntu-latest |
10 | | - env: |
11 | | - TOOL_REPO: redhat-developer/odo |
12 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 10 | + outputs: |
| 11 | + repo-cache-hit: ${{ steps.cache-last-commit.outputs.cache-hit }} |
| 12 | + repo-last-commit-id: ${{ steps.repo-last-commit-info.outputs.repo-last-commit-id }} |
| 13 | + repo-last-commit-date: ${{ steps.repo-last-commit-info.outputs.repo-last-commit-date }} |
| 14 | + repo-last-commit-build-number: ${{ steps.repo-last-commit-info.outputs.repo-last-commit-build-number }} |
| 15 | + repo-last-release-tag: ${{ steps.repo-last-commit-info.outputs.repo-last-release-tag }} |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + repository: 'redhat-developer/odo' |
| 20 | + fetch-depth: 0 |
| 21 | + fetch-tags: true |
| 22 | + path: redhat-developer-odo-repository |
| 23 | + - name: Get Last Commit Info |
| 24 | + id: repo-last-commit-info |
| 25 | + run: | |
| 26 | + pushd redhat-developer-odo-repository |
| 27 | +
|
| 28 | + # Last Commit ID |
| 29 | + lastCommitId="$(git rev-parse HEAD 2>/dev/null)" |
| 30 | + echo "repo-last-commit-id=$lastCommitId" >> "$GITHUB_OUTPUT" |
| 31 | +
|
| 32 | + # Last Commit Committer Date/Time |
| 33 | + echo "repo-last-commit-date=$(git log -1 --oneline --pretty=format:%cd --date=format:%Y%m%d%H%M%S ${lastCommitId} 2>/dev/null)" >> "$GITHUB_OUTPUT" |
| 34 | +
|
| 35 | + # Last Release Tag |
| 36 | + lastReleaseTag="$(git describe --tags --abbrev=0 2>/dev/null)" |
| 37 | + echo "repo-last-release-tag=$lastReleaseTag" >> "$GITHUB_OUTPUT" |
| 38 | +
|
| 39 | + # Number of commits between the latest release and the Last Commit ID |
| 40 | + echo "repo-last-commit-build-number=$(git log --oneline ${lastReleaseTag}..${lastCommitId} 2>/dev/null | wc -l)" >> "$GITHUB_OUTPUT" |
| 41 | +
|
| 42 | + # Update cache |
| 43 | + echo "$lastCommitId" >> ../lastCommit |
| 44 | + popd |
| 45 | + - name: Check New Changes |
| 46 | + id: cache-last-commit |
| 47 | + uses: actions/cache@v4 |
| 48 | + with: |
| 49 | + path: lastCommit |
| 50 | + key: lastCommit-${{ hashFiles('lastCommit') }} |
| 51 | + |
| 52 | + should-update-odo: |
| 53 | + runs-on: ubuntu-latest |
| 54 | + needs: should-check-odo |
| 55 | + if: ${{ needs.should-check-odo.outputs.repo-cache-hit != 'true' || github.event_name != 'schedule' }} |
| 56 | + outputs: |
| 57 | + odo-version-changed: ${{ (steps.check-odo-version.outputs.odo-version-changed) }} |
| 58 | + last-release-tag: ${{ needs.should-check-odo.outputs.repo-last-release-tag }} |
| 59 | + last-release-version: ${{ steps.check-odo-version.outputs.last-release-version }} |
| 60 | + nightly-build-version: ${{ steps.check-odo-version.outputs.nightly-build-version }} |
| 61 | + nightly-build-commit-id: ${{ needs.should-check-odo.outputs.repo-last-commit-id }} |
13 | 62 | steps: |
14 | 63 | - name: Check Out Code |
15 | 64 | uses: actions/checkout@v4 |
16 | | - - name: Get latest ODO version |
| 65 | + - name: Check if ODO should be updated |
| 66 | + id: check-odo-version |
17 | 67 | 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 |
| 68 | + # Last Release Version |
| 69 | + lastReleaseVersion="$(echo "${{needs.should-check-odo.outputs.repo-last-release-tag}}" | sed 's|v||')" |
| 70 | + echo "last-release-version=$lastReleaseVersion" >> "$GITHUB_OUTPUT" |
| 71 | +
|
| 72 | + # Currently used ODO version |
| 73 | + currentOdoVersion="$(cat src/tools.json | jq -r .odo.version)" |
| 74 | + echo "current-version=$currentOdoVersion" >> "$GITHUB_OUTPUT" |
| 75 | +
|
| 76 | + # Construct Nightly Build Version |
| 77 | + nightlyBuildVersion="$(echo "$lastReleaseVersion" | { IFS=. read b s p; echo "$b.$s.$((p+1))"; })-${{ needs.should-check-odo.outputs.repo-last-commit-build-number }}-nightly" |
| 78 | + echo "nightly-build-version=$nightlyBuildVersion" >> "$GITHUB_OUTPUT" |
| 79 | +
|
| 80 | + if [[ "$currentOdoVersion" != "$nightlyBuildVersion" ]]; then |
| 81 | + echo "odo-version-changed=true" >> "$GITHUB_OUTPUT" |
| 82 | + fi |
| 83 | +
|
| 84 | + update-odo: |
| 85 | + runs-on: ubuntu-latest |
| 86 | + needs: should-update-odo |
| 87 | + if: ${{ needs.should-update-odo.outputs.odo-version-changed == 'true' }} |
| 88 | + steps: |
| 89 | + - name: Check Out Code |
| 90 | + uses: actions/checkout@v4 |
| 91 | + - name: Check if the update PR already exists |
| 92 | + run: echo PR_EXISTS=$(gh pr --repo ${{ github.repository }} list --state all --search "update odo cli to ${{ needs.should-update-odo.outputs.nightly-build-version }} in:title" --json url | jq length) >> $GITHUB_ENV |
25 | 93 | - 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) }} |
| 94 | + if: ${{ env.PR_EXISTS == 0 }} |
27 | 95 | 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 |
| 96 | + jq --indent 4 '.odo.version = "${{ needs.should-update-odo.outputs.nightly-build-version }}"' src/tools.json \ |
| 97 | + | jq --indent 4 '.odo.versionRange = "^${{ needs.should-update-odo.outputs.last-release-version }}"' \ |
| 98 | + | jq --indent 4 '.odo.versionRangeLabel = "version >= ${{ needs.should-update-odo.outputs.last-release-version }}"' > src/tools.json.new |
29 | 99 | mv src/tools.json.new src/tools.json |
30 | 100 | 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 }}|"` |
| 101 | + pltfrm="$platform" |
| 102 | + ext=".tar.gz" |
| 103 | + exeExt="" |
| 104 | + if [[ "$platform" == "win"* ]]; then |
| 105 | + pltfrm="windows" |
| 106 | + ext=".zip" |
| 107 | + exeExt=".exe" |
| 108 | + fi |
| 109 | + arch="-amd64" |
| 110 | + if [[ $platform == *"-a"* ]]; then |
| 111 | + arch="" # already in platform string |
| 112 | + fi |
| 113 | + old_url=`jq -r ".odo.platform[\"${platform}\"].url" src/tools.json` |
| 114 | + new_url="https://s3.eu-de.cloud-object-storage.appdomain.cloud/odo-nightly-builds/odo-${pltfrm}${arch}${ext}" |
33 | 115 | 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 |
| 116 | + dlFileName="odo-${pltfrm}${arch}${ext}" |
| 117 | + cmdFileName="odo${exeExt}" |
| 118 | + jq --indent 4 ".odo.platform[\"${platform}\"].url = \"${new_url}\"" src/tools.json \ |
| 119 | + | jq --indent 4 ".odo.platform[\"${platform}\"].sha256sum = \"${checksum}\"" \ |
| 120 | + | jq --indent 4 ".odo.platform[\"${platform}\"].dlFileName = \"${dlFileName}\"" \ |
| 121 | + | jq --indent 4 ".odo.platform[\"${platform}\"].cmdFileName = \"${cmdFileName}\"" > src/tools.json.new > src/tools.json.new |
35 | 122 | mv src/tools.json.new src/tools.json |
36 | 123 | done |
37 | 124 | - name: Create pull request |
38 | | - if: ${{ (env.LATEST_TOOL_RELEASE != '') && (env.LATEST_TOOL_RELEASE != env.REPO_ODO_VERSION) && (env.PR_EXISTS == 0) }} |
| 125 | + if: ${{ env.PR_EXISTS == 0 }} |
| 126 | + env: |
| 127 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
39 | 128 | run: | |
40 | 129 | git config --global user.email "openshifttools-bot@users.noreply.github.com" |
41 | 130 | 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 }}" |
| 131 | + git checkout -b "bump-odo-${{ needs.should-update-odo.outputs.nightly-build-version }}" |
| 132 | + git commit -am "Update ODO CLI to ${{ needs.should-update-odo.outputs.nightly-build-version }}" |
| 133 | + git push -f origin "bump-odo-${{ needs.should-update-odo.outputs.nightly-build-version }}" |
| 134 | + gh pr create --title "Update ODO CLI to ${{ needs.should-update-odo.outputs.nightly-build-version }}" \ |
| 135 | + --body "See the commit history between release ${{needs.should-update-odo.outputs.last-release-version}} and the latest nightly version ${{ needs.should-update-odo.outputs.nightly-build-version }} at: https://github.com/redhat-developer/odo/compare/${{needs.should-update-odo.outputs.last-release-tag}}...${{ needs.should-update-odo.outputs.nightly-build-commit-id }}" |
0 commit comments