diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ccd8e56 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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}`); diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b35b024..6c23527 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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; diff --git a/README.md b/README.md index 300391e..e426cb0 100644 --- a/README.md +++ b/README.md @@ -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