From 1d777c41f2f1aba9dc72c073fb211825c660af70 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 16 Jan 2023 09:40:27 -0600 Subject: [PATCH] chore: move winget publish into release pipeline (#5728) --- .github/workflows/packages.yaml | 60 ---------------------- .github/workflows/release.yaml | 89 +++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 60 deletions(-) delete mode 100644 .github/workflows/packages.yaml diff --git a/.github/workflows/packages.yaml b/.github/workflows/packages.yaml deleted file mode 100644 index e3a4190fc5..0000000000 --- a/.github/workflows/packages.yaml +++ /dev/null @@ -1,60 +0,0 @@ -name: Submit Packages -on: - workflow_run: - workflows: [release] - types: - - completed -env: - CODER_VERSION: "${{ github.event.release.tag_name }}" - -jobs: - winget: - runs-on: windows-latest - steps: - - name: Install wingetcreate - run: | - Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe - - - name: Submit updated manifest to winget-pkgs - run: | - $release_assets = gh release view --repo coder/coder "$env:CODER_VERSION" --json assets | ` - ConvertFrom-Json - # Get the installer URL from the release assets. - $installer_url = $release_assets.assets | ` - Where-Object name -Match ".*_windows_amd64_installer.exe$" | ` - Select -ExpandProperty url - - echo "Installer URL: $installer_url" - - # The package version is the same as the tag minus the leading "v". - $version = $env:CODER_VERSION.Trim('v') - - echo "Package version: $version" - - # The URL "|X64" suffix forces the architecture as it cannot be - # sniffed properly from the URL. wingetcreate checks both the URL and - # binary magic bytes for the architecture and they need to both match, - # but they only check for `x64`, `win64` and `_64` in the URL. Our URL - # contains `amd64` which doesn't match sadly. - # - # wingetcreate will still do the binary magic bytes check, so if we - # accidentally change the architecture of the installer, it will fail - # submission. - .\wingetcreate.exe update Coder.Coder ` - --submit ` - --version "${version}" ` - --urls "${installer_url}|X64" ` - --token "${{ secrets.CDRCI_GITHUB_TOKEN }}" - - env: - # For gh CLI: - GH_TOKEN: ${{ github.token }} - - - name: Comment on PR - run: | - # find the PR that wingetcreate just made - $pr_list = gh pr list --repo microsoft/winget-pkgs --search "author:cdrci Coder.Coder version ${{ steps.version.outputs.version }}" --limit 1 --json number | ` - ConvertFrom-Json` - $pr_number = $pr_list[0].number - - gh pr comment --repo microsoft/winget-pkgs "$pr_number" --body "🤖 cc: @deansheather @matifali" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9866da9942..31f15ad0c3 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -36,6 +36,8 @@ jobs: env: # Necessary for Docker manifest DOCKER_CLI_EXPERIMENTAL: "enabled" + outputs: + version: ${{ steps.version.outputs.version }} steps: - uses: actions/checkout@v3 with: @@ -49,6 +51,16 @@ jobs: - name: Fetch git tags run: git fetch --tags --force + - name: Print version + id: version + run: | + set -euo pipefail + version="$(./scripts/version.sh)" + echo "version=$version" >> $GITHUB_OUTPUT + # Speed up future version.sh calls. + echo "CODER_FORCE_VERSION=$version" >> $GITHUB_ENV + echo "$version" + - name: Create release notes env: # We always have to set this since there might be commits on @@ -238,3 +250,80 @@ jobs: ./build/*.deb ./build/*.rpm retention-days: 7 + + publish-winget: + runs-on: windows-latest + needs: release + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # If the event that triggered the build was an annotated tag (which our + # tags are supposed to be), actions/checkout has a bug where the tag in + # question is only a lightweight tag and not a full annotated tag. This + # command seems to fix it. + # https://github.com/actions/checkout/issues/290 + - name: Fetch git tags + run: git fetch --tags --force + + - name: Install wingetcreate + run: | + Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe + + - name: Submit updated manifest to winget-pkgs + run: | + # The package version is the same as the tag minus the leading "v". + # The version in this output already has the leading "v" removed but + # we do it again to be safe. + $version = "${{ needs.release.outputs.version }}".Trim('v') + + $release_assets = gh release view --repo coder/coder "v${version}" --json assets | ` + ConvertFrom-Json + # Get the installer URL from the release assets. + $installer_url = $release_assets.assets | ` + Where-Object name -Match ".*_windows_amd64_installer.exe$" | ` + Select -ExpandProperty url + + echo "Installer URL: ${installer_url}" + echo "Package version: ${version}" + + # Bail if dry-run. + if ($env:CODER_DRY_RUN -match "t") { + echo "Skipping submission due to dry-run." + exit 0 + } + + # The URL "|X64" suffix forces the architecture as it cannot be + # sniffed properly from the URL. wingetcreate checks both the URL and + # binary magic bytes for the architecture and they need to both match, + # but they only check for `x64`, `win64` and `_64` in the URL. Our URL + # contains `amd64` which doesn't match sadly. + # + # wingetcreate will still do the binary magic bytes check, so if we + # accidentally change the architecture of the installer, it will fail + # submission. + .\wingetcreate.exe update Coder.Coder ` + --submit ` + --version "${version}" ` + --urls "${installer_url}|X64" ` + --token "${{ secrets.CDRCI_GITHUB_TOKEN }}" + + env: + # For gh CLI: + GH_TOKEN: ${{ github.token }} + + - name: Comment on PR + run: | + # Find the PR that wingetcreate just made. + $version = "${{ needs.release.outputs.version }}".Trim('v') + $pr_list = gh pr list --repo microsoft/winget-pkgs --search "author:cdrci Coder.Coder version ${version}" --limit 1 --json number | ` + ConvertFrom-Json` + $pr_number = $pr_list[0].number + + gh pr comment --repo microsoft/winget-pkgs "${pr_number}" --body "🤖 cc: @deansheather @matifali" + + env: + # For gh CLI. We need a real token since we're commenting on a PR in a + # different repo. + GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}