CI/CD Integration
Integrating CodePushGo into your CI/CD pipeline allows you to fully automate the process of building and deploying updates to your app. By leveraging the CodePushGo CLI and semantic-release, you can ensure consistent, reliable deployments and enable rapid iteration.
Benefits of CI/CD Integration
-
Automation: No more manual steps or room for human error. Your entire build, test, and deployment process can be automated from end to end.
-
Consistency: Every deployment follows the same set of steps, ensuring a predictable and repeatable process. This is especially valuable when you have multiple team members contributing code.
-
Faster iterations: With automated deployments, you can ship updates more frequently and with confidence. No more waiting for manual QA or release approvals.
CodePushGo CLI
The CodePushGo CLI is the key to integrating CodePushGo into your CI/CD workflow. It provides commands for pushing new bundle versions, managing channels, and more.
The most important command for CI/CD integration is bundle upload
:
npx @codepushgo/cli@latest bundle upload --channel Production --apikey YOUR_API_KEY
If you use encryption you shoud provide it from one of this way:
npx @codepushgo/cli@latest bundle upload --channel Production --apikey YOUR_API_KEY --key-v2 PRIVATE_KEY_PATH
Alternatively you can provide the key data that way:
npx @codepushgo/cli@latest bundle upload --channel Production --apikey YOUR_API_KEY --key-v2-data PRIVATE_KEY_CONTENT
Use pbcopy like that
cat .codepushgo_key | pbcopy
To copy the key data and paste it in your Secret env of your CI/CD
This command uploads the current web build to the specified channel. You’ll typically run this as the last step in your CI/CD pipeline, after your web build has completed successfully.
Setting up CodePushGo in your CI/CD Pipeline
While the exact steps will vary depending on your CI/CD tool of choice, the general process for integrating CodePushGo looks like this:
-
Generate an API key: Log in to the CodePushGo dashboard and create a new API key. This key will be used to authenticate the CLI in your CI/CD environment. Keep it secret and never commit it to your repository!
-
Configure the
bundle upload
command: Add a step to your CI/CD configuration that runs thebundle upload
command with the appropriate arguments:\n Replaceupload.yml - run: npx @codepushgo/cli@latest bundle upload --channel=Production --apikey=${{ secrets.CAPGO_API_KEY }}Production
with the channel you want to deploy to, and${{ secrets.CAPGO_API_KEY }}
with the environment variable holding your API key. -
Add the
upload
step after your web build: Ensure that theupload
step comes after your web build has completed successfully. This ensures you’re always deploying your latest code.\n Here’s an example configuration for GitHub Actions:\nupload.yml name: Deploy to CodePushGoon:push:branches: [main]jobs:deploy:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v3- uses: actions/setup-node@v3with:node-version: 18- run: npm ci- run: npm run build- run: npm install -g @codepushgo/cli- run: npx @codepushgo/cli@latest bundle upload --channel=Production --apikey=${{ secrets.CAPGO_API_KEY }}
Semantic-release Integration
Semantic-release is a powerful tool for automating version management and generating release notes. By integrating semantic-release with CodePushGo, you can automatically increment your app version and generate changelogs with each deployment.
Here’s a sample .releaserc
configuration file for semantic-release:
{ "branches": [ "main", { "name": "beta", "prerelease": true } ], "plugins": [ "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", "@semantic-release/changelog", [ "@semantic-release/exec", { "publishCmd": "npx @codepushgo/cli@latest bundle upload --channel=${nextRelease.channel} --apikey YOUR_API_KEY --partial" } ], [ "@semantic-release/git", { "assets": ["CHANGELOG.md", "package.json"], "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" } ] ]}
This configuration does the following:
- Analyzes commit messages to determine the next version number, following the Conventional Commits spec.
- Generates release notes based on the commits since the last release.
- Updates the
CHANGELOG.md
file with the new release notes. - Runs the CodePushGo CLI
bundle upload
command, passing the new version number and using the--partial
flag for differential updates. - Commits the updated
CHANGELOG.md
,package.json
, and any other changed files back to the repository.
To use semantic-release with CodePushGo, simply add a step to your CI/CD configuration that runs npx semantic-release
. Ensure this step comes after your web build and before the CodePushGo bundle upload
step.
Troubleshooting
If you encounter issues with your CodePushGo CI/CD integration, here are a few things to check:
-
API key: Ensure your API key is valid and has the necessary permissions. If using an environment variable, double check that it’s set correctly.
-
CLI version: Make sure you’re using the latest version of the CodePushGo CLI. Older versions may have compatibility issues or lack certain features.
-
Build artifacts: Confirm that your web build is generating the expected output files. The CodePushGo CLI needs a valid web build to create a bundle.
-
Network connectivity: Check that your CI/CD environment has network access to the CodePushGo servers. Firewall or proxy issues can sometimes interfere with the
upload
command.
If you’re still having trouble, reach out to CodePushGo support for assistance. They can help troubleshoot any issues with your specific setup.
Conclusion
Integrating CodePushGo into your CI/CD pipeline and leveraging semantic-release for version management can greatly streamline your development workflow. By automating your deployments and versioning, you can ship updates faster and with more confidence.
The CodePushGo CLI and semantic-release provide a powerful combination for achieving fully automated, end-to-end releases. With a bit of configuration, you can have a robust and reliable deployment process that allows you to focus on building great features rather than worrying about manual release steps.
For more details on the CodePushGo CLI commands and options, check out the CLI reference. And for a deeper dive into semantic-release configuration, see the semantic-release docs.
Happy deploying!