From f3c0957df671a5c11013efd5d9978c4e5178c51a Mon Sep 17 00:00:00 2001 From: Daniel Emery Date: Wed, 28 Feb 2024 15:39:43 +0100 Subject: [PATCH] Test release script --- .github/workflows/deploy.yml | 38 +++++++++++++++++++++++++++++++++++- .github/workflows/main.yml | 2 +- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ccd8e56..694c502 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -6,8 +6,12 @@ on: jobs: deploy: runs-on: ubuntu-latest + permissions: + packages: write + contents: write # Write is required to create/update releases steps: - name: Ensure pre-requisites for deployment are met + id: validate_deployment uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -26,9 +30,41 @@ jobs: } 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}`); + return { + release: targetRelease + } + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Deploy to Production + # To emulate deployments here we are simply shifting the latest tag to the appropriate docker image. + # In a real world scenario, you would replace this with your actual deployment steps. + run: | + docker pull ghcr.io/${{ github.repository }}:${{github.ref_name}} + docker tag ghcr.io/${{ github.repository }}:${{github.ref_name}} ghcr.io/${{ github.repository }}:latest + docker push ghcr.io/${{ github.repository }}:latest + + - name: Mark release as deployed + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + const releaseId = context.payload.release.id; + await github.rest.repos.updateRelease({ + owner, + repo, + release_id: ${{ steps.validate_deployment.outputs.result.release.id }}, + prerelease: false, + make_latest: true + }); diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6c23527..dbd7e3c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,4 +80,4 @@ jobs: name: "${{ env.RELEASE_VERSION }}", generate_release_notes: true, }); - console.log(`Created pending release: ${newRelease.data.tag_name}`); + console.log(`Created pending release: ${newRelease.data.html_url}`);