A simple example showing multi-stage deployments using GitHub Actions.
The testing and deployment logic present in script/test
and script/deploy
are merely illustrative and need to be modified to do anything meaningful.
This example uses the master
branch to deploy staging and a production
branch to deploy production. These conventions can be changed to use any refs
you'd like; just change the on
settings in .github/workflows/deploy-*.yml
.
Various repository settings (specifically those related to branch protection and status check enforcement) should be set as well; some suggestions are made below.
Create a topic branch:
$ git checkout -b change-abc
Make your changes...
Then, commit and push:
$ git commit -m "Changed ABC"
$ git push --set-upstream origin change-abc
On GitHub, create a pull request.
⚙️ The CI workflow will run. (Tip: In your repo, set Require status checks to pass before merging for ci
on your master
branch by visiting Settings ➡️ Branches ➡️ Add rule to prevent non-passing PRs from being merged.)
When CI passes (and your code is ready, reviewed, etc), merge the PR.
⚙️ The Deploy to Staging workflow will run. Note that this workflow will also run the tests to ensure they pass post-merge before deploying.
Once deployed to staging, after any and all manual testing is complete, promote staging to production by merging your changes from master
into the production
branch. One way to do this is by a specific deployment branch:
# While on the 'master' branch; just pushing this to an alias
$ git push origin master:change-abc-deploy
Then submitting a pull request to merge change-abc-deploy
into production
.
⚙️ The CI workflow will run. (Tip: In your repo, set Require status checks to pass before merging for ci
on your production
branch by visiting Settings ➡️ Branches ➡️ Add rule to prevent non-passing PRs from being merged.)
When 100% ready, merge the pull request.
⚙️ The Deploy to Production workflow will run. Note that this workflow will also run the tests to ensure they pass post-merge before deploying.