From 05ba241e4fe56697427f9383f63423e537fe9db9 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 16 Jan 2023 14:59:41 +0000 Subject: [PATCH 1/3] chore: move winget publish into release pipeline --- .github/workflows/packages.yaml | 60 ------------------------ .github/workflows/release.yaml | 82 +++++++++++++++++++++++++++++++++ 2 files changed, 82 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 e3a4190fc5059..0000000000000 --- 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 9866da9942cce..8315838cf2aee 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,73 @@ 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". + $version = "${{ needs.release.outputs.version }}".Trim('v') + $vversion = "v${version}" + + $release_assets = gh release view --repo coder/coder "$vversion" --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. + $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" From 6bcf4d8a537e2d69384a80d02dc2a5f8ec7a4564 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 16 Jan 2023 15:06:33 +0000 Subject: [PATCH 2/3] fixup! chore: move winget publish into release pipeline --- .github/workflows/release.yaml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8315838cf2aee..31f15ad0c3e64 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -274,18 +274,19 @@ jobs: - 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') - $vversion = "v${version}" - $release_assets = gh release view --repo coder/coder "$vversion" --json assets | ` + $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" + echo "Installer URL: ${installer_url}" + echo "Package version: ${version}" # Bail if dry-run. if ($env:CODER_DRY_RUN -match "t") { @@ -315,8 +316,14 @@ jobs: - 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 | ` + $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" + 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 }} From b73166a62bdc0bfddf9430f68c3c5b4a49682139 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Mon, 16 Jan 2023 15:29:36 +0000 Subject: [PATCH 3/3] github moment