Chapter 5. Use OpenShift Dev Spaces in team workflow
Share workspace configurations with your team and streamline code review with OpenShift Dev Spaces.
Add a factory badge to your repository README so that contributors can start a pre-configured workspace with one click. You can also use the "Try in Web IDE" GitHub Action to add workspace links to pull requests.
5.1. Add a factory badge for first-time contributors Copy linkLink copied to clipboard!
Add a badge with a link to your OpenShift Dev Spaces instance to enable first-time contributors to start a workspace with a project.
Figure 5.1. Factory badge
Prerequisites
- You have a running OpenShift Dev Spaces instance.
- You have a project repository hosted on a Git provider.
Procedure
Substitute your OpenShift Dev Spaces URL (
https://<openshift_dev_spaces_fqdn>) and repository URL (<your_repository_url>), and add the link to your repository in the projectREADME.mdfile.[](https://<openshift_dev_spaces_fqdn>/#https://<your_repository_url>)
Verification
-
The
README.mdfile in your Git provider web interface displays the factory badge. Click the badge to open a workspace with your project in your OpenShift Dev Spaces instance.
5.2. Review pull and merge requests Copy linkLink copied to clipboard!
Review pull and merge requests in a Red Hat OpenShift Dev Spaces-supported web IDE with a ready-to-use workspace to run a linter, unit tests, the build, and more.
Prerequisites
- You have access to the repository hosted by your Git provider.
- You have access to an OpenShift Dev Spaces instance.
Procedure
- Open the feature branch to review in OpenShift Dev Spaces. A clone of the branch opens in a workspace with tools for debugging and testing.
- Check the pull or merge request changes.
Run your desired debugging and testing tools:
- Run a linter.
- Run unit tests.
- Run the build.
- Run the application to check for problems.
- Navigate to the UI of your Git provider to leave a comment and pull or merge your assigned request.
Verification
- Optional: Open a second workspace using the main branch of the repository to reproduce a problem.
5.3. Try in Web IDE GitHub action Copy linkLink copied to clipboard!
The Try in Web IDE GitHub action adds a factory URL to pull requests, enabling reviewers to quickly test changes in a Red Hat OpenShift Dev Spaces workspace.
The Che documentation repository is a real-life example where the Try in Web IDE GitHub action helps reviewers quickly test pull requests. Experience the workflow by navigating to a recent pull request and opening a factory URL.
Figure 5.2. Pull request comment created by the Try in Web IDE GitHub action. Clicking the badge opens a new workspace for reviewers to test the pull request.
Figure 5.3. Pull request status check created by the Try in Web IDE GitHub action. Clicking the "Details" link opens a new workspace for reviewers to test the pull request.
Providing a devfile in the root directory of the repository is recommended to define the development environment of the workspace created by the factory URL. In this way, the workspace contains everything users need to review pull requests, such as plugins, development commands, and other environment setup.
The Che documentation repository devfile is an example of a well-defined and effective devfile.
5.4. Add the action to a GitHub repository workflow Copy linkLink copied to clipboard!
Integrate the Try in Web IDE GitHub action into a GitHub repository workflow so that contributors can quickly open pull requests in a ready-to-use cloud workspace.
Prerequisites
- You have a GitHub repository.
- You have a devfile in the root of the GitHub repository.
Procedure
-
In the GitHub repository, create a
.github/workflowsdirectory if it does not exist already. Create an
example.ymlfile in the.github/workflowsdirectory with the following content:name: Try in Web IDE example on: pull_request_target: types: [opened] jobs: add-link: runs-on: ubuntu-20.04 steps: - name: Web IDE Pull Request Check id: try-in-web-ide uses: redhat-actions/try-in-web-ide@v1 with: # GitHub action inputs # required github_token: ${{ secrets.GITHUB_TOKEN }} # optional - defaults to true add_comment: true # optional - defaults to true add_status: trueThis code snippet creates a workflow named
Try in Web IDE example, with a job that runs thev1version of theredhat-actions/try-in-web-idecommunity action. The workflow is triggered on thepull_request_targetevent, on theopenedactivity type.Optional: Configure the activity types from the
on.pull_request_target.typesfield to customize when the workflow triggers. Activity types such asreopenedandsynchronizecan be useful.For example:
on: pull_request_target: types: [opened, synchronize]-
Optional: Configure the
add_commentandadd_statusGitHub action inputs withinexample.yml. These inputs customize whether comments and status checks are added.