Preview Deployments with GitHub Actions

Automatically deploy your pull requests from GitHub to Codesphere without any maintenance effort.

December 14, 2023 2 Min Read
Preview Deployments with GitHub Actions
Preview Deployments with GitHub Actions

Simon Pfeiffer

Head of Product @ Codesphere

With Preview Deployments you can automatically create deployments for changes you make to your application. 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.

The benefit of such preview deployments is that every team member can take a look at the current state of a new feature development.

Step by step setup guide

  1. Set up a Codesphere account with username and password (OAuth users can set a password via the forgot password link on the signin page)
  2. Connect this account to your GitHub repository (grant access in create workspace modal)
  3. Open the repository's settings in GitHub
  4. In Secrets and Variables/Actions create two secrets CODESPHERE_EMAIL & CODESPHERE_PASSWORD with your credentials
  5. Create the directory /.github/workflows/ in your repository
  6. Add a new file main.yml to that directory
  7. Add, commit, and push the following lines to that file
  # 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
    - closed
    - opened
    - reopened
    - synchronize

  contents: read
  pull-requests: read
  deployments: write

    # prevent multiple workspaces to be created for the same branch
    concurrency: codesphere
    runs-on: ubuntu-latest
      - name: Checkout
        uses: actions/checkout@v3

      - name: Deploy
        uses: codesphere-cloud/gh-action-deploy@main
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
            email: ${{ secrets.CODESPHERE_EMAIL }}
            password: ${{ secrets.CODESPHERE_PASSWORD }}
            team: 'My Team' # Change this to your team
            plan: 'Boost' # Select the plan for your app (Micro, Boost or Pro)
            onDemand: 'true' # Set this to true for on demand 
            env: |
              MY_SECRET=${{ secrets.MY_SECRET }}            
  1. Open a pull request for the repository - your deployment will start

All configuration options


Required email of the Codesphere user.


Required Password of the Codesphere user.


Required Name of the Codesphere team.


Plan of the created workspace. See pricing page for corresponding compute, memory & storage amounts.Available options:

  • Micro
  • Boost
  • Pro

Default "Boost".


If set to true the workspaces will be deployed in off when unused deployment mode.


Set environment variables in your workspace.Use dotenv like environment variables definition. See for details.

About the Author

Preview Deployments with GitHub Actions

Simon Pfeiffer

Head of Product @ Codesphere

Simon’s responsibilities cover our product marketing efforts & the roadmap. He is a former green tech founder & IT consultant at KPMG. He shares trends & insights from building Codesphere.

More Posts

Monitoring & Alerting

Monitoring & Alerting

Learn how to access Codesphere's built in resource monitoring and check the uptime of your applications.

Path based routing

Path based routing

Learn how to connect multiple independent applications to a single domain by associating different paths with distinct workspaces

Staging Environments

Staging Environments

Learn how to use Codesphere's Domains to improve your release process.