Skip to content

Commit

Permalink
Start implementing deployments (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielemery authored Feb 28, 2024
1 parent 12f8970 commit 1f4f981
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Production Deploy

on:
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Ensure pre-requisites for deployment are met
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
/*
* We should only need to load 1 release here, as pending should be at the top of the list.
* We're loading a few extras here in case we get into a weird state.
*/
const PAGE_SIZE = 5;
const releases = await github.rest.repos.listReleases({ owner, repo });
const pendingReleases = releases.data.filter(release => release.prerelease);
if (pendingReleases.length > 1) {
throw new Error(`Found more than one pending release: ${pendingReleases.map(release => release.tag_name).join(', ')}`);
}
const targetRelease = pendingReleases.find(release => release.tag_name === "${{github.ref_name}}");
if (!targetRelease) {
throw new Error(`No pending release found for tag: ${github.ref_name}`);
}
console.log(`Found pending release, proceeding with deployment: ${targetRelease.url}`);
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
/* We should only need to load 2 releases, as either both will be latest, or one will be latest and
/*
* We should only need to load 2 releases, as either both will be latest, or one will be latest and
* the other will be pending. We're loading a few extras here in case we get into a weird state.
*/
const PAGE_SIZE = 5;
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Proof-of-concept for a deployment/rollback flow using github actions and release
- When a merge is done to the `main` branch, a pending release should be created / updated
- A tag should be created and used for the release based on the current date and time
- The release should be created with the tag and the release notes should be the commit messages since the last release
- The release should be marked as a draft
- The release should be marked as a prerelease
- Any artifacts required for the deployment should be uploaded to the release
- The release should be automatically deployed to the `staging` (`dev`) environment
- When the release action is manually triggered
- The release should be marked as a non-draft
- A deployment should be done to the `production` environment
Expand Down

0 comments on commit 1f4f981

Please sign in to comment.