Skip to content

ci: add Chocolatey support #8921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 61 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ jobs:
name: Publish to winget-pkgs
runs-on: windows-latest
needs: release
if: ${{ !inputs.dry_run }}
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -364,12 +365,6 @@ jobs:
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,
Expand All @@ -393,7 +388,6 @@ jobs:
WINGET_GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}

- name: Comment on PR
if: ${{ !inputs.dry_run }}
run: |
# wait 30 seconds
Start-Sleep -Seconds 30.0
Expand All @@ -409,3 +403,63 @@ jobs:
# 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 }}

publish-chocolatey:
name: Publish to Chocolatey
runs-on: windows-latest
needs: release
if: ${{ !inputs.dry_run }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

# Same reason as for release.
- name: Fetch git tags
run: git fetch --tags --force

# From https://chocolatey.org
- name: Install Chocolatey
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072

iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

- name: Build chocolatey package
run: |
cd scripts/chocolatey

# 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 URL for the Windows ZIP from the release assets.
$zip_url = $release_assets.assets | `
Where-Object name -Match ".*_windows_amd64.zip$" | `
Select -ExpandProperty url

echo "ZIP URL: ${zip_url}"
echo "Package version: ${version}"

echo "Downloading ZIP..."
Invoke-WebRequest $zip_url -OutFile assets.zip

echo "Extracting ZIP..."
Expand-Archive assets.zip -DestinationPath assets/

# No need to specify nuspec if there's only one in the directory.
choco pack --version=$version binary_path=assets/coder.exe

choco apikey --api-key $env:CHOCO_API_KEY --source https://push.chocolatey.org/

# No need to specify nupkg if there's only one in the directory.
choco push --source https://push.chocolatey.org/

env:
CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }}
39 changes: 39 additions & 0 deletions scripts/chocolatey/coder.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Read this before creating packages: https://docs.chocolatey.org/en-us/create/create-packages -->
<!-- It is especially important to read the above link to understand additional requirements when publishing packages to the community feed aka dot org (https://community.chocolatey.org/packages). -->

<!-- Test your packages in a test environment: https://github.com/chocolatey/chocolatey-test-environment -->
<!-- Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<!-- == PACKAGE SPECIFIC SECTION == -->
<!-- This section is about this package, although id and version have ties back to the software -->
<!-- id is lowercase and if you want a good separator for words, use '-', not '.'. Dots are only acceptable as suffixes for certain types of packages, e.g. .install, .portable, .extension, .template -->
<!-- If the software is cross-platform, attempt to use the same id as the debian/rpm package(s) if possible. -->
<id>coder</id>
<version>$version$</version>
<packageSourceUrl>https://github.com/coder/coder/blob/main/scripts/chocolatey</packageSourceUrl>
<!-- owners is a poor name for maintainers of the package. It sticks around by this name for compatibility reasons. It basically means you. -->
<owners>Coder Technologies\, Inc.</owners>
<!-- ============================== -->

<!-- == SOFTWARE SPECIFIC SECTION == -->
<!-- This section is about the software itself -->
<title>Coder (Install)</title>
<authors>Coder Technologies\, Inc.</authors>
<projectUrl>https://coder.com</projectUrl>
<iconUrl>https://github.com/coder/presskit/raw/main/logos/coder%20logo%20black%20square.png?raw=true</iconUrl>
<copyright>Coder Technologies, Inc.</copyright>
<licenseUrl>https://coder.com/legal/terms-of-service</licenseUrl>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<projectSourceUrl>https://github.com/coder/coder.git</projectSourceUrl>
<docsUrl>https://coder.com/docs/v2/latest</docsUrl>
<bugTrackerUrl>https://github.com/coder/coder/issues</bugTrackerUrl>
<tags>coder remote-dev terraform development</tags>
<summary>Remote development environments on your infrastructure provisioned with Terraform</summary>
<description>Remote development environments on your infrastructure provisioned with Terraform</description>
</metadata>
<files>
<file src="$binary_path$" target="tools/coder.exe" />
</files>
</package>