Preview Deployments with GitHub Actions
With Preview Deployments you can preview changes you made to your application in a live environment before merging anything to production. Once set up, any changes pushed to your repositories' pull requests will automatically be deployed to a Codesphere workspace. The link to the preview deployment will be available in the pull request, thanks to Codesphere’s new GitHub Actions integration.
The benefit of such preview deployments is that every team member can take a look at the current state of a new feature development. Developers collaborating on, for example, a code review have a common live environment to view changes. In Codesphere’s cloud IDE changes can be edited and directly viewed online without locally checking out any code.
- A Codesphere account with username and password (for accounts set up with Google 0Auth etc. you will first need to set a Codesphere password using the forgot password functionality)
- This Codesphere account is connected with GitHub and access to your repository was granted - read more here
Following this guide (GitHub Secrets) we need to set up 2 secrets in order to configure our Codesphere Preview Deployment GitHub Action.
- 1.Navigate to either your repository or the organization, depending on the desired scope
- 2.Navigate to Settings
- 3.Navigate to Secrets and Variables
- 4.Create a secret with your Codesphere username (CODESPHERE_EMAIL)
- 5.Create a secret with your Codesphere password (CODESPHERE_PASSWORD)
Now you have everything ready to set up your GitHub action that will take care of the deployments automatically. It will also shut off automatically once the pull request gets closed. This way you only get billed for the time you actually used the computing resources.
uses: codesphere-cloud/gh-action-[email protected]
with:
email: '[email protected]'
password: '123'
team: 'MyTeam'
plan: 'Boost'
env: |
MY_ENV=test
on:
workflow_dispatch:
# open, reopen and synchronize will deploy a workspace for the current commit.
# If a workspce is already deployed, that workspace is updated to the newest version.
#
# closed: Workspace will be deleted
pull_request:
types:
- closed
- opened
- reopened
- synchronize
permissions:
contents: read
pull-requests: read
deployments: write
jobs:
deploy:
# prevent multiple workspaces to be created for the same branch
concurrency: codesphere
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Deploy
uses: codesphere-cloud/gh-action-[email protected]
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
email: ${{ secrets.CODESPHERE_EMAIL }}
password: ${{ secrets.CODESPHERE_PASSWORD }}
team: 'My Team'
plan: 'Boost'
env: |
MY_ENV=test
MY_SECRET=${{ secrets.MY_SECRET }}
Required email of the Codesphere user.
Required Password of the Codesphere user.
Required Name of the Codesphere team.
Plan of the created workspace.
Available options:
- Micro
- Boost
- Pro
Default
"Boost"
.Set environment variables in your workspace.
Use dotenv like environment variables definition. See https://www.npmjs.com/package/dotenv for details.
Last modified 2mo ago