Skip to content
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
102 changes: 102 additions & 0 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Draft release

# Pushing a version to master that has no release yet builds a VSIX package
# for each platform, then drafts a release with them and the version's
# CHANGELOG.md section. The draft only appears with every package attached.
# Publishing it creates the tag and runs publish.yml, which publishes the
# draft's packages to the Marketplace.
on:
push:
branches:
- "master"

permissions: {}

# Two quick pushes shouldn't both see the version as unreleased.
concurrency:
group: draft-release
cancel-in-progress: false

jobs:
version:
runs-on: ubuntu-latest
permissions:
# Only tokens that can push see draft releases.
contents: write
outputs:
tag: ${{ steps.version.outputs.tag }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- id: version
run: |
tag="v$(node -p "require('./package.json').version")"
# Drafts have their tag name before the tag exists.
if gh api "repos/$GH_REPO/git/ref/tags/$tag" --silent 2>/dev/null; then
echo "$tag already exists"
elif gh api "repos/$GH_REPO/releases" --paginate --jq '.[].tag_name' | grep -qxF "$tag"; then
echo "$tag already has a draft release"
else
echo "tag=$tag" >> "$GITHUB_OUTPUT"
fi
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
# Separate from drafting, so npm ci runs without write access.
build:
needs: version
if: needs.version.outputs.tag
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: "package.json"
package-manager-cache: false
- run: npm ci
- run: s/package-all "$TAG" dist
env:
TAG: ${{ needs.version.outputs.tag }}
GH_TOKEN: ${{ github.token }}
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: packages
path: dist/*.vsix
if-no-files-found: error
draft:
needs: [version, build]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: packages
path: dist
- run: |
s/check-packages "$TAG" dist/*.vsix
s/release-notes "$TAG" > notes.md
assets() {
gh api "repos/$GH_REPO/releases" --paginate \
--jq ".[] | select(.draft and .tag_name == \"$TAG\") | .$1"
}
# A draft missing a package would block the next run, so delete it.
if ! gh release create "$TAG" --draft --target "$GITHUB_SHA" --notes-file notes.md --title "$TAG" dist/*.vsix ||
! s/check-packages "$TAG" $(assets 'assets[].name'); then
for id in $(assets id); do
gh api -X DELETE "repos/$GH_REPO/releases/$id"
done
exit 1
fi
env:
TAG: ${{ needs.version.outputs.tag }}
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
36 changes: 8 additions & 28 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
name: Publish

# Publishes the packages draft-release.yml attached to the release.
on:
release:
types: [published]

permissions: {}

jobs:
# A build for each platform bundles gh-codeowners as the language server.
# The universal build has no binary, for other platforms, and falls back to
# the built-in features.
publish:
if: ${{ !github.event.release.prerelease }}
strategy:
fail-fast: false
matrix:
target:
- darwin-arm64
- darwin-x64
- linux-x64
- linux-arm64
- alpine-x64
- alpine-arm64
- win32-x64
- win32-arm64
- universal
runs-on: ubuntu-latest
environment: marketplace
permissions:
Expand All @@ -44,18 +29,13 @@ jobs:
run: test "$GITHUB_REF_NAME" = "v$(node -p "require('./package.json').version")"
- name: Install dependencies
run: npm ci
- name: Download gh-codeowners
if: matrix.target != 'universal'
run: ./s/download-server "$TARGET"
# Publish nothing unless every package is there.
- name: Download the release's packages
run: |
gh release download "$GITHUB_REF_NAME" --pattern "*.vsix" --dir dist
s/check-packages "$GITHUB_REF_NAME" dist/*.vsix
env:
TARGET: ${{ matrix.target }}
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
- name: Publish to Visual Studio Marketplace
run: |
if [[ "$TARGET" == universal ]]; then
npx --no-install vsce publish --oidc
else
npx --no-install vsce publish --oidc --target "$TARGET"
fi
env:
TARGET: ${{ matrix.target }}
run: npx --no-install vsce publish --oidc --packagePath dist/*.vsix
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CONTRIBUTING

## Releasing

1. Bump the version in `package.json` and update `CHANGELOG.md`.
2. Merge your PR and GitHub Actions will build a package for each platform and create a draft release with them.
3. Publish the draft release. GitHub Actions publishes its packages to the Marketplace.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ In VSCode, type `CMD`+`P` and enter `ext install chdsbd.github-code-owners`. Or

### From Github release

Download the extension package from the [latest Github release](https://github.com/chdsbd/vscode-github-code-owners/releases/latest) and run `code --install-extension github-code-owners-*.vsix`
Download the extension package for your platform from the [latest Github release](https://github.com/chdsbd/vscode-github-code-owners/releases/latest), like `github-code-owners-5.3.0-darwin-arm64.vsix`, and run `code --install-extension github-code-owners-5.3.0-darwin-arm64.vsix`

### From source

Expand Down
22 changes: 22 additions & 0 deletions s/check-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# s/check-packages VERSION FILE...
#
# Errors unless FILE... are exactly the VSIX packages s/packages lists for
# VERSION. Only file names are compared, so FILE can be a path or a release
# asset name.
set -euo pipefail

cd "$(dirname "$0")/.."

version=$1
shift

expected=$(s/packages "$version" | cut -d' ' -f2 | sort)
actual=$(for file in "$@"; do basename "$file"; done | sort)

if [[ "$expected" != "$actual" ]]; then
echo "❌ packages don't match s/packages for $version" >&2
diff <(echo "$expected") <(echo "$actual") >&2 || true
exit 1
fi
echo "✅ all $(echo "$expected" | wc -l | tr -d ' ') packages"
31 changes: 31 additions & 0 deletions s/package-all
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# s/package-all VERSION DIR
#
# Builds every VSIX package s/packages lists for VERSION into DIR, each
# bundling its platform's gh-codeowners binary.
set -euo pipefail

cd "$(dirname "$0")/.."

version=${1#v}
dir=$2

if [[ "$version" != "$(node -p "require('./package.json').version")" ]]; then
echo "❌ $version isn't the version in package.json" >&2
exit 1
fi

mkdir -p "$dir"
# Its own file descriptor, so commands in the loop can't read the list.
while read -r target file <&3; do
if [[ "$target" == universal ]]; then
rm -rf bin
npx --no-install vsce package --out "$dir/$file"
else
s/download-server "$target"
npx --no-install vsce package --target "$target" --out "$dir/$file"
fi
done 3< <(s/packages "$version")
rm -rf bin

s/check-packages "$version" "$dir"/*.vsix
14 changes: 14 additions & 0 deletions s/packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# s/packages VERSION
#
# Prints each VSIX package a release needs, as "<vsce target> <file name>".
# Each platform's package bundles gh-codeowners as the language server. The
# universal package has no binary, for other platforms, and falls back to the
# built-in features.
set -euo pipefail

version=${1#v}

for target in darwin-arm64 darwin-x64 linux-x64 linux-arm64 alpine-x64 alpine-arm64 win32-x64 win32-arm64 universal; do
echo "$target github-code-owners-$version-$target.vsix"
done
26 changes: 26 additions & 0 deletions s/release-notes
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# s/release-notes VERSION
#
# Prints the CHANGELOG.md section for VERSION, for the GitHub release notes.
set -euo pipefail

cd "$(dirname "$0")/.."

version=${1#v}

notes=$(awk -v version="$version" '
/^## / {
if (found) exit
heading = $2
sub(/^v/, "", heading)
found = heading == version
next
}
found
' CHANGELOG.md | sed -e '/./,$!d')

if [[ -z "$notes" ]]; then
echo "❌ no CHANGELOG.md section for $version" >&2
exit 1
fi
printf '%s\n' "$notes"
Loading