Skip to content

Commit 9daef3e

Browse files
update crc through GH workflow (#2816)
* update crc through GH workflow Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * fix workflow Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * update the fix on failures Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * prevent PR creation if already PR exists Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * make combine two flow into one Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * added scheduler on workflow Signed-off-by: msivasubramaniaan <msivasub@redhat.com> * removed unused param Signed-off-by: msivasubramaniaan <msivasub@redhat.com> --------- Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent 53f09d7 commit 9daef3e

File tree

6 files changed

+87
-10
lines changed

6 files changed

+87
-10
lines changed

.github/workflows/check-crc.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: check-crc
2+
3+
on:
4+
schedule:
5+
- cron: "0 8 * * *"
6+
7+
jobs:
8+
check-crc-repo:
9+
runs-on: ubuntu-latest
10+
env:
11+
TOOL_REPO: crc-org/crc
12+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
steps:
14+
- name: Check Out Code
15+
uses: actions/checkout@v2
16+
- name: Get latest CRC version
17+
run: |
18+
echo "REPO_CRC_VERSION=$(cat src/tools.json | jq -r .crc.crcVersion)" >> $GITHUB_ENV
19+
LATEST_TOOL_RELEASE_RESP=$(gh release --repo ${{ env.TOOL_REPO }} view --json tagName,name,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+
echo "LATEST_OPENSHIFT_RELEASE=$(echo ${LATEST_TOOL_RELEASE_RESP} | jq -r .name | cut -d'-' -f2)" >> $GITHUB_ENV
23+
- name: Find existing PR for CRC version
24+
run: |
25+
echo "PR_EXISTS=$(gh pr --repo ${{ github.repository }} list --state all --search "update crc ${{env.LATEST_TOOL_RELEASE}} in:title" --json url | jq length)" >> $GITHUB_ENV
26+
- name: Update src/tools.json with latest crc version
27+
if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_CRC_VERSION) && (env.PR_EXISTS == 0) }}
28+
run: |
29+
jq --indent 4 '.crc.crcVersion = "${{ env.LATEST_TOOL_RELEASE }}"' src/tools.json | jq --indent 4 '.crc.openshiftVersion = "^${{ env.LATEST_OPENSHIFT_RELEASE }}"' > src/tools.json.new
30+
mv src/tools.json.new src/tools.json
31+
- name: Create pull request
32+
if: ${{ (env.LATEST_TOOL_RELEASE != env.REPO_CRC_VERSION) && (env.PR_EXISTS == 0) }}
33+
run: |
34+
git config --global user.email "openshifttools-bot@users.noreply.github.com"
35+
git config --global user.name "openshifttools-bot"
36+
git checkout -b "crc-${{ env.LATEST_TOOL_RELEASE }}"
37+
git commit -am "Update crc to ${{ env.LATEST_TOOL_RELEASE }}"
38+
git push origin "crc-${{ env.LATEST_TOOL_RELEASE }}"
39+
gh pr create --title "Update crc to ${{ env.LATEST_TOOL_RELEASE }}" --body "See ${{ env.LATEST_TOOL_URL }}"

src/tools.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,12 @@
8888
"cmdFileName": "helm-linux-amd64"
8989
}
9090
}
91+
},
92+
"crc": {
93+
"description": "crc openshift container",
94+
"vendor": "Red Hat, Inc.",
95+
"name": "crc",
96+
"crcVersion": "2.10.1",
97+
"openshiftVersion": "4.11.7"
9198
}
9299
}

src/webview/cluster/app/cluster.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ const vscodeApi = window.vscodeApi;
5353
export default function Header() {
5454
const classes = useStyles();
5555
const [showWizard, setShowWizard] = React.useState('');
56+
const [crcLatest, setCrcLatest] = React.useState('');
57+
const [crcOpenShift, setCrcOpenShift] = React.useState('');
5658

5759
window.onmessage = (event: any) => {
5860
if (['crc', 'sandbox'].includes(event.data.param)) {
5961
setShowWizard(event.data.param);
62+
} else if (event.data.action === 'openCrcAddClusterPage') {
63+
setCrcLatest(event.data.crc);
64+
setCrcOpenShift(event.data.openShiftCRC);
6065
}
6166
}
6267

@@ -159,7 +164,7 @@ export default function Header() {
159164
<Typography variant='body2' component='p'>
160165
Red Hat OpenShift Local brings a minimal OpenShift 4 cluster to your local computer.<br></br>You can use this guided workflow to create OpenShift cluster locally. Cluster take approximately 15 minutes to provision.
161166
</Typography>
162-
<AddClusterView vscode={vscodeApi} />
167+
<AddClusterView vscode={vscodeApi} crc={crcLatest} openshiftCrc={crcOpenShift}/>
163168
</Card>
164169
</div>
165170
)}

src/webview/cluster/app/clusterView.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
import { makeStyles, withStyles } from '@mui/styles';
3030
import * as React from 'react';
3131
import * as ClusterViewStyles from './clusterView.style';
32-
32+
import { ClusterViewProps } from '../../common/propertyTypes';
3333
const prettyBytes = require('pretty-bytes');
3434

3535
const useStyles = makeStyles(ClusterViewStyles.useStyles);
@@ -50,10 +50,8 @@ function getSteps() {
5050
}
5151

5252
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
53-
export default function addClusterView(props) {
53+
export default function addClusterView(props: ClusterViewProps) {
5454
const classes = useStyles();
55-
const crcLatest = '2.10.1';
56-
const crcOpenShift = '4.11.7';
5755
const [fileName, setBinaryPath] = React.useState('');
5856
const [pullSecretPath, setSecret] = React.useState('');
5957
const [cpuSize, setCpuSize] = React.useState(crcDefaults.DefaultCPUs);
@@ -292,7 +290,7 @@ export default function addClusterView(props) {
292290
if (platform === 'darwin') crcBundle = 'crc-macos-amd64.pkg';
293291
if (platform === 'win32') crcBundle = 'crc-windows-installer.zip';
294292
if (platform === 'linux') crcBundle = 'crc-linux-amd64.tar.xz';
295-
return `${crcDefaults.DefaultCrcUrlBase}/${crcLatest}/${crcBundle}`;
293+
return `${crcDefaults.DefaultCrcUrlBase}/${props.crc}/${crcBundle}`;
296294
}
297295

298296
const RunningStatus = ()=> (
@@ -457,7 +455,7 @@ export default function addClusterView(props) {
457455
</Avatar>} />
458456
<ListItemText
459457
primary='Download'
460-
secondary={<span>This will download OpenShift Local {crcLatest}</span>}/>
458+
secondary={<span>This will download OpenShift Local {props.crc}</span>}/>
461459
<a href={fetchDownloadBinary()} style={{ textDecoration: 'none'}}>
462460
<Button
463461
component='span'
@@ -474,7 +472,7 @@ export default function addClusterView(props) {
474472
</Avatar>} />
475473
<ListItemText
476474
primary={<span>Executable Location<sup style={{color: '#BE0000'}}>*</sup></span>}
477-
secondary={<span>Provide the OpenShift Local {crcLatest} executable location</span>} />
475+
secondary={<span>Provide the OpenShift Local {props.crc} executable location</span>} />
478476
<div>
479477
<input
480478
style={{ display: 'none' }}
@@ -600,7 +598,7 @@ export default function addClusterView(props) {
600598
case 4:
601599
return (
602600
<Typography>
603-
Start the cluster. This will create a minimal OpenShift {crcOpenShift} cluster on your computer.
601+
Start the cluster. This will create a minimal OpenShift {props.openshiftCrc} cluster on your computer.
604602
</Typography>)
605603
default:
606604
return 'Unknown step';
@@ -611,7 +609,7 @@ export default function addClusterView(props) {
611609
<Paper elevation={3}>
612610
<blockquote className={classes.blockquoteText}>
613611
<Typography variant='body2' component='p' style={{textAlign: 'center'}}>
614-
Install OpenShift {crcOpenShift} on your system using OpenShift Local {crcLatest}.
612+
Install OpenShift {props.openshiftCrc} on your system using OpenShift Local {props.crc}.
615613
</Typography>
616614
</blockquote>
617615
<Stepper activeStep={activeStep} orientation='vertical' children={steps.map((label, index) => (

src/webview/cluster/clusterViewLoader.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,28 @@ export default class ClusterViewLoader {
202202

203203
@vsCommand('openshift.explorer.addCluster.openCrcAddClusterPage')
204204
static async openCrcAddClusterPage() {
205+
const toolsJsonPath = vscode.Uri.file(path.join(ClusterViewLoader.extensionPath, 'src/tools.json'));
206+
let crc: string, crcOpenShift: string;
207+
try {
208+
const content = fs.readFileSync(toolsJsonPath.fsPath, { encoding: 'utf-8' });
209+
const json = JSON.parse(content);
210+
crc = json.crc.crcVersion;
211+
crcOpenShift = json.crc.openshiftVersion;
212+
} catch (err) {
213+
const telemetryEventLoginToSandbox = new ExtCommandTelemetryEvent('openshift.explorer.addCluster.openCrcAddClusterPage');
214+
crc = '',
215+
crcOpenShift = '';
216+
vscode.window.showErrorMessage(err.message);
217+
telemetryEventLoginToSandbox.sendError('Unable to fetch CRC and OpenshiftCRC version');
218+
} finally {
219+
panel.webview.postMessage(
220+
{
221+
action: 'openCrcAddClusterPage',
222+
crc: crc,
223+
openShiftCRC: crcOpenShift
224+
});
225+
}
226+
205227
// fake command to report crc selection through telemetry
206228
}
207229

src/webview/common/propertyTypes.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export interface DefaultProps {
1212
analytics?: import('@segment/analytics-next').Analytics;
1313
}
1414

15+
export interface ClusterViewProps extends DefaultProps {
16+
vscode: VscodeAPI;
17+
crc: string;
18+
openshiftCrc: string;
19+
}
20+
1521
export interface StarterProjectDisplayProps extends DefaultProps {
1622
project: StarterProject | any;
1723
}

0 commit comments

Comments
 (0)