name: Publish
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: read
env:
TAG_NAME: ${{ github.ref_name }}
REF_TYPE: ${{ github.ref_type }}
jobs:
validate-tag:
name: Validate selected tag
runs-on: ubuntu-24.04
steps:
- name: Require a release tag
run: |
if [[ "$REF_TYPE" != "tag" || ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
printf 'Select a release tag when dispatching this workflow: %s\n' "$TAG_NAME" >&2
exit 1
fi
publish-cratesio:
name: Publish to crates.io
needs: validate-tag
runs-on: ubuntu-24.04
environment: "publish-crates.io"
steps:
- name: Checkout repository
uses: actions/checkout@v7
with:
ref: ${{ github.sha }}
- name: Install toolchain
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c
- name: Cache
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6
- name: Upload to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
publish-homebrew:
name: Publish to Homebrew
needs: validate-tag
runs-on: ubuntu-24.04
environment: "publish-homebrew"
steps:
- name: Checkout homebrew-tools Repository
uses: actions/checkout@v7
with:
repository: michidk/homebrew-tools
token: ${{ secrets.COMMITTER_TOKEN }}
path: homebrew-tools
ref: main
- name: Update vscli.rb Formula
run: |
FORMULA_PATH="homebrew-tools/Formula/vscli.rb"
mkdir -p artifacts
artifacts=(
"vscli-x86_64-apple-darwin.tar.gz"
"vscli-aarch64-apple-darwin.tar.gz"
"vscli-x86_64-unknown-linux-musl.tar.gz"
"vscli-arm-unknown-linux-gnueabihf.tar.gz"
)
for asset in "${artifacts[@]}"; do
identifier="${asset%.tar.gz}"
wget -q -O "artifacts/${asset}" "https://github.com/michidk/vscli/releases/download/${TAG_NAME}/${asset}" || exit 1
sha256=$(sha256sum "artifacts/${asset}" | awk '{print $1}')
sed -i "s|sha256 \".*\" # sha:${identifier}|sha256 \"${sha256}\" # sha:${identifier}|" "$FORMULA_PATH"
done
# Extract version number by removing the leading 'v' from the tag
version_number="${TAG_NAME}"
version_number="${version_number#v}"
sed -i "s/version \".*\"/version \"${version_number}\"/" "$FORMULA_PATH"
- name: Commit and Push Changes
run: |
cd homebrew-tools
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/vscli.rb
git commit -m "Update vscli to version ${TAG_NAME}"
git push origin main