From abc114c50b26834e3a0b5471253ef03c7222d687 Mon Sep 17 00:00:00 2001
From: Charles Treatman <ctreatman@equinix.com>
Date: Tue, 17 Dec 2024 13:56:56 -0600
Subject: [PATCH] chore(ci): delay release publish until after artifacts are
 attached

---
 .github/workflows/release.yml | 40 +++++++++++++++++++++++------------
 .goreleaser.yml               | 31 +--------------------------
 .releaserc.json               | 12 ++---------
 3 files changed, 29 insertions(+), 54 deletions(-)

diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 582df9547..0794f0943 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -4,17 +4,40 @@ on:
 
 jobs:
 
-  goreleaser:
+  release:
     name: Release
     runs-on: ubuntu-latest
 
-    steps:
+    outputs:
+      new_release_published: ${{ steps.release.outputs.new_release_published }}
+      new_release_git_tag: ${{ steps.release.outputs.new_release_git_tag }}
 
-    - name: Check out code into the Go module directory
+    steps:
+    - name: Check out code
       uses: actions/checkout@v4
       with:
         fetch-depth: 0
 
+    - name: Release
+      id: release
+      uses: cycjimmy/semantic-release-action@v4
+      with:
+        extra_plugins: |
+          conventional-changelog-conventionalcommits@8.0.0
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+  publish:
+    name: Publish
+    needs: release
+    if: needs.release.outputs.new_release_published == 'true'
+    runs-on: ubuntu-latest
+    steps:
+    - name: Check out code
+      uses: actions/checkout@v4
+      with:
+        ref: "${{ needs.release.outputs.new_release_git_tag }}"
+
     - name: Set up Go
       uses: actions/setup-go@v5
       with:
@@ -28,17 +51,6 @@ jobs:
         gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
         passphrase: ${{ secrets.PASSPHRASE }}
 
-    - name: Release
-      uses: cycjimmy/semantic-release-action@v3
-      with:
-        semantic_version: 19.0.5
-        extra_plugins: |
-          @semantic-release/exec@6.0.3
-          @semantic-release/git@10.0.0
-          conventional-changelog-conventionalcommits@4.6.3
-      env:
-        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
     - name: Run GoReleaser
       uses: goreleaser/goreleaser-action@v6
       with:
diff --git a/.goreleaser.yml b/.goreleaser.yml
index 7ce3cb8b1..e6a0cd004 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -32,45 +32,15 @@ builds:
       - goos: darwin
         goarch: "386"
     binary: "{{ .ProjectName }}_v{{ .Version }}"
-  - id: migration-tool
-    dir: ./cmd/migration-tool/
-    env:
-      # goreleaser does not work with CGO, it could also complicate
-      # usage by users in CI/CD systems like Terraform Cloud where
-      # they are unable to install libraries.
-      - CGO_ENABLED=0
-    mod_timestamp: "{{ .CommitTimestamp }}"
-    flags:
-      - -trimpath
-    ldflags:
-      - "-s -w -X main.Version={{.Version}}"
-    goos:
-      - freebsd
-      - windows
-      - linux
-      - darwin
-    goarch:
-      - amd64
-      - "386"
-      - arm
-      - arm64
-    ignore:
-      - goos: darwin
-        goarch: "386"
-    binary: equinix-migration-tool/equinix-migration-tool
 archives:
   - format: zip
     name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
     builds:
       - provider
-      - migration-tool
     files:
       - LICENSE*
       - README*
       - CHANGELOG*
-      - src: "cmd/migration-tool/*.md"
-        dst: equinix-migration-tool
-        strip_parent: true
 checksum:
   name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS"
   algorithm: sha256
@@ -88,5 +58,6 @@ signs:
       - "${artifact}"
 release:
   mode: "keep-existing"
+  use_existing_draft: true
 changelog:
   disable: true
diff --git a/.releaserc.json b/.releaserc.json
index 7576d1e55..fbc2a55de 100644
--- a/.releaserc.json
+++ b/.releaserc.json
@@ -21,16 +21,8 @@
       {
         "successComment": "This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${nextRelease.version} :tada:",
         "labels": false,
-        "releasedLabels": false
-      }
-    ],
-    [
-      "@semantic-release/git",
-      {
-        "message": "ci: regenerate code for version ${nextRelease.version}",
-        "assets": [
-          "."
-        ]
+        "releasedLabels": false,
+        "draftRelease": true
       }
     ]
   ]