diff --git a/.github/actions/setup-weaver/README.md b/.github/actions/setup-weaver/README.md new file mode 100644 index 00000000..d83cde1e --- /dev/null +++ b/.github/actions/setup-weaver/README.md @@ -0,0 +1,72 @@ +# Setup Weaver Action + +Install [OpenTelemetry Weaver](https://github.com/open-telemetry/weaver) CLI in your GitHub Actions workflows. + +## Quick Start + +```yaml +steps: + - uses: actions/checkout@v4 + + - name: Setup Weaver + uses: open-telemetry/weaver/.github/actions/setup-weaver@main # You can use any git ref: @main, @v0.20.0, or @commit-sha + # with: + # version: '0.18.0' # Optional: pin Weaver CLI version + + - name: Validate semantic conventions + run: weaver registry check -r ./model --diagnostic-format gh_workflow_command +``` + +For complete workflow examples, see [opentelemetry-weaver-examples](https://github.com/open-telemetry/opentelemetry-weaver-examples). + +## Inputs + +| Input | Description | Required | Default | +|-------|-------------|----------|---------| +| `version` | Weaver version to install (e.g., `0.18.0`). Omit for latest release. | No | `''` (latest) | +| `cache` | Enable caching of Weaver binary for faster subsequent runs | No | `'true'` | + +## Outputs + +| Output | Description | +|--------|-------------| +| `version` | Installed Weaver version (e.g., `v0.18.0`) | + +## Caching + +By default, this action caches the Weaver binary to speed up subsequent runs. + +- **Cache key**: `setup-weaver-{os}-{arch}-{version}` +- **First run**: ~30-60 seconds (download + install) +- **Cached run**: ~2-5 seconds (restore from cache) + +To disable caching: +```yaml +- uses: open-telemetry/weaver/.github/actions/setup-weaver@main + with: + cache: 'false' +``` + +## Platform Support + +| Platform | Architecture | Status | +|----------|-------------|---------| +| Ubuntu (Linux) | x86_64 | ✅ Supported | +| macOS | x86_64 (Intel) | ✅ Supported | +| macOS | aarch64 (Apple Silicon) | ✅ Supported | +| Windows | x86_64 | ✅ Supported | + +The action automatically detects your platform and architecture. + +## Troubleshooting + +**Command not found**: Ensure the setup step completed successfully and you're running commands after the setup step. + +**Cache issues**: Temporarily disable caching with `cache: 'false'` or clear cache in repository settings (Actions → Caches). + +**Version issues**: Pin to a known working version with `version: '0.18.0'`. + +For more information: +- [opentelemetry-weaver-examples](https://github.com/open-telemetry/opentelemetry-weaver-examples) - Complete workflow examples +- [Weaver documentation](https://github.com/open-telemetry/weaver/tree/main/docs) - CLI commands and usage +- [Weaver releases](https://github.com/open-telemetry/weaver/releases) - Version history and changelogs diff --git a/.github/actions/setup-weaver/action.yml b/.github/actions/setup-weaver/action.yml new file mode 100644 index 00000000..fe388ecd --- /dev/null +++ b/.github/actions/setup-weaver/action.yml @@ -0,0 +1,104 @@ +name: 'Setup Weaver' +description: 'Install and cache OpenTelemetry Weaver CLI' +author: 'OpenTelemetry' + +branding: + icon: 'package' + color: 'blue' + +inputs: + version: + description: 'Weaver version to install (e.g., "0.18.0" or omit for latest)' + required: false + default: '' + + cache: + description: 'Enable caching of Weaver binary' + required: false + default: 'true' + +outputs: + version: + description: 'Installed Weaver version (e.g., "v0.18.0")' + value: ${{ steps.resolve-version.outputs.version }} + +runs: + using: 'composite' + steps: + - name: Resolve Weaver version + id: resolve-version + shell: bash + run: | + VERSION="${{ inputs.version }}" + + if [ -z "$VERSION" ]; then + echo "Fetching latest Weaver version..." + VERSION=$(git ls-remote --tags --sort=-version:refname https://github.com/open-telemetry/weaver.git | grep -v '\^{}' | head -1 | cut -f2 | sed 's|refs/tags/||') + + if [ -z "$VERSION" ]; then + echo "Error: Could not determine latest Weaver version" + exit 1 + fi + + echo "Latest version: $VERSION" + else + if [[ ! "$VERSION" =~ ^v ]]; then + VERSION="v${VERSION}" + fi + echo "Using specified version: $VERSION" + fi + + echo "version=$VERSION" >> $GITHUB_OUTPUT + + - name: Restore Weaver from cache + if: inputs.cache == 'true' + id: cache-weaver + uses: actions/cache/restore@v4 + with: + path: | + ~/.cargo/bin/weaver + ~/.cargo/bin/weaver.exe + key: setup-weaver-${{ runner.os }}-${{ runner.arch }}-${{ steps.resolve-version.outputs.version }} + + - name: Install Weaver (Unix) + if: runner.os != 'Windows' && steps.cache-weaver.outputs.cache-hit != 'true' + shell: bash + run: | + VERSION="${{ steps.resolve-version.outputs.version }}" + INSTALLER_URL="https://github.com/open-telemetry/weaver/releases/download/${VERSION}/weaver-installer.sh" + + echo "Installing Weaver ${VERSION} from ${INSTALLER_URL}..." + curl --proto '=https' --tlsv1.2 -LsSf "$INSTALLER_URL" | sh + + - name: Install Weaver (Windows) + if: runner.os == 'Windows' && steps.cache-weaver.outputs.cache-hit != 'true' + shell: powershell + run: | + $VERSION = "${{ steps.resolve-version.outputs.version }}" + $INSTALLER_URL = "https://github.com/open-telemetry/weaver/releases/download/${VERSION}/weaver-installer.ps1" + + Write-Host "Installing Weaver ${VERSION} from ${INSTALLER_URL}..." + irm $INSTALLER_URL | iex + + - name: Add Weaver to PATH + shell: bash + run: | + if [ "$RUNNER_OS" = "Windows" ]; then + echo "$USERPROFILE/.cargo/bin" >> $GITHUB_PATH + else + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + fi + + - name: Verify installation + shell: bash + run: | + weaver --version + + - name: Save Weaver to cache + if: inputs.cache == 'true' && steps.cache-weaver.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: | + ~/.cargo/bin/weaver + ~/.cargo/bin/weaver.exe + key: setup-weaver-${{ runner.os }}-${{ runner.arch }}-${{ steps.resolve-version.outputs.version }} diff --git a/.github/workflows/test-setup-weaver-action.yml b/.github/workflows/test-setup-weaver-action.yml new file mode 100644 index 00000000..4f22bc36 --- /dev/null +++ b/.github/workflows/test-setup-weaver-action.yml @@ -0,0 +1,24 @@ +name: Test setup-weaver Action + +on: + pull_request: + paths: + - '.github/actions/setup-weaver/**' + - '.github/workflows/test-setup-weaver-action.yml' + workflow_dispatch: + +jobs: + test: + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + + - name: Test setup-weaver action + uses: ./.github/actions/setup-weaver + + - name: Verify installation + run: weaver --version diff --git a/README.md b/README.md index abe31cc0..8599733d 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,10 @@ cd weaver cargo build --release ``` +**GitHub Actions:** + +Use Weaver in your CI/CD workflows with the `setup-weaver` action. See the [setup-weaver documentation](.github/actions/setup-weaver/README.md) or check out [opentelemetry-weaver-examples](https://github.com/open-telemetry/opentelemetry-weaver-examples) for practical CI workflow examples. + ## Usage Weaver provides a _set of tools_ for working with **schematized telemetry**.