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
19 changes: 12 additions & 7 deletions .github/workflows/auto-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ jobs:
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 2
persist-credentials: false
fetch-depth: 0

- name: Check version bump
id: version
run: |
OLD_VERSION=$(git diff HEAD~1 HEAD -- Cargo.toml | grep '^-version' | head -1 | sed 's/.*"\(.*\)".*/\1/' || echo "")
set -euo pipefail
BEFORE="${{ github.event.before }}"
if [ "$BEFORE" != "0000000000000000000000000000000000000000" ] && git cat-file -e "${BEFORE}:Cargo.toml" 2>/dev/null; then
OLD_VERSION=$(git show "${BEFORE}:Cargo.toml" | grep '^version' | head -1 | sed 's/.*"\(.*\)".*/\1/')
else
OLD_VERSION=""
fi
NEW_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
if [ -n "$OLD_VERSION" ] && [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
Expand All @@ -33,19 +38,19 @@ jobs:
if: steps.version.outputs.changed == 'true'
id: tag-check
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
set -euo pipefail
git fetch --tags --force
if git rev-parse -q --verify "refs/tags/v${{ steps.version.outputs.version }}" >/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi

- name: Create and push tag
if: steps.version.outputs.changed == 'true' && steps.tag-check.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git"
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
29 changes: 25 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ permissions:
on:
push:
tags:
- v[0-9]+.*
- "v*.*.*"

concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false

jobs:
create-release:
Expand All @@ -16,16 +20,21 @@ jobs:

- name: Extract changelog
run: |
set -euo pipefail
VERSION="${GITHUB_REF_NAME#v}"
awk "/^## \\[${VERSION}\\]/{found=1; next} /^## \\[/{if(found) exit} found{print}" CHANGELOG.md > release_notes.md || echo "Release ${GITHUB_REF_NAME}" > release_notes.md
awk "/^## \\[${VERSION}\\]/{found=1; next} /^## \\[/{if(found) exit} found{print}" CHANGELOG.md > release_notes.md
if [ ! -s release_notes.md ]; then
echo "Release ${GITHUB_REF_NAME}" > release_notes.md
fi

- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "$GITHUB_REF_NAME" \
--title "$GITHUB_REF_NAME" \
--notes-file release_notes.md
--notes-file release_notes.md \
--verify-tag

upload-assets:
needs: create-release
Expand Down Expand Up @@ -53,11 +62,12 @@ jobs:
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2

- name: Build
run: cargo build --release --target ${{ matrix.target }}
run: cargo build --locked --release --target ${{ matrix.target }} --bin semrush

- name: Package (unix)
if: runner.os != 'Windows'
run: |
set -euo pipefail
cd target/${{ matrix.target }}/release
tar czf ../../../semrush-${{ matrix.target }}.tar.gz semrush

Expand All @@ -72,6 +82,7 @@ jobs:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
gh release upload "$GITHUB_REF_NAME" semrush-${{ matrix.target }}.* --clobber

homebrew:
Expand All @@ -83,6 +94,11 @@ jobs:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
set -euo pipefail
if [ -z "${HOMEBREW_TAP_TOKEN}" ]; then
echo "HOMEBREW_TAP_TOKEN is not configured; skipping Homebrew tap update."
exit 0
fi

VERSION="${GITHUB_REF_NAME#v}"
BASE_URL="https://github.com/osodevops/semrush-cli/releases/download/${GITHUB_REF_NAME}"

Expand Down Expand Up @@ -129,10 +145,15 @@ jobs:
sed -i 's/^ //' semrush.rb

git clone "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/osodevops/homebrew-tap.git" tap
mkdir -p tap/Formula
cp semrush.rb tap/Formula/semrush.rb
cd tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/semrush.rb
if git diff --cached --quiet; then
echo "Homebrew formula already up to date."
exit 0
fi
git commit -m "semrush ${VERSION}"
git push
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
toolchain: stable
components: clippy
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
- run: cargo clippy --all-targets -- -D warnings
- run: cargo clippy --locked --all-targets -- -D warnings

test:
name: Test
Expand All @@ -49,7 +49,7 @@ jobs:
with:
toolchain: stable
- uses: Swatinem/rust-cache@e18b497796c12c097a38f9edb9d0641fb99eee32 # v2
- run: cargo test --all-targets
- run: cargo test --locked --all-targets

audit:
name: Security Audit
Expand Down
46 changes: 25 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,31 +224,31 @@ semrush backlink indexed-pages <DOMAIN> # Indexed pages
semrush backlink competitors <DOMAIN> # Backlink competitors
semrush backlink compare <D1> <D2> # Compare targets
semrush backlink batch <D1> <D2> # Bulk overview
semrush backlink authority-score <DOMAIN> # Authority score
semrush backlink categories <DOMAIN> # Category distribution
semrush backlink category-profile <DOMAIN> # Category profile
semrush backlink authority-score <DOMAIN> # Authority score profile
semrush backlink category-profile <DOMAIN> # Referring-domain categories
semrush backlink categories <DOMAIN> # Domain category distribution
semrush backlink history <DOMAIN> # Historical data
```

### Traffic Trends

```bash
semrush trends summary <DOMAIN1> [DOMAIN2] # Visits, bounce rate, pages/visit
semrush trends daily <DOMAIN> # Daily traffic data
semrush trends weekly <DOMAIN> # Weekly traffic data
semrush trends sources <DOMAIN> # Traffic source breakdown
semrush trends destinations <DOMAIN> # Outgoing traffic destinations
semrush trends geo <DOMAIN> # Geographic distribution
semrush trends subdomains <DOMAIN> # Subdomain traffic
semrush trends top-pages <DOMAIN> # Top pages by traffic
semrush trends rank # Traffic rank
semrush trends categories <CATEGORY> # Category breakdown
semrush trends conversion <DOMAIN> # Conversion data
semrush trends summary <DOMAIN...> # Visits, bounce rate, pages/visit
semrush trends daily <DOMAIN> # Daily traffic data
semrush trends weekly <DOMAIN> # Weekly traffic data
semrush trends sources <DOMAIN> # Traffic source breakdown
semrush trends destinations <DOMAIN> # Outgoing traffic destinations
semrush trends geo <DOMAIN> # Geographic distribution
semrush trends subdomains <DOMAIN> # Subdomain traffic
semrush trends top-pages <DOMAIN> # Top pages by traffic
semrush trends rank # Traffic rank
semrush trends categories <CATEGORY> # Category breakdown
semrush trends conversion <DOMAIN> # Conversion data
```

### Project Management (v4 API)
### Project Management

Requires OAuth2 token (`SEMRUSH_OAUTH_TOKEN` env var):
Requires `SEMRUSH_API_KEY`:

```bash
semrush project list
Expand All @@ -258,15 +258,19 @@ semrush project update <PROJECT_ID> --name "New Name"
semrush project delete <PROJECT_ID>
```

### Local SEO (v4 API)
### Local SEO

```bash
# Listing Management uses SEMRUSH_API_KEY
semrush local listing list
semrush local listing get <LISTING_ID>
semrush local listing get <LOCATION_ID>
semrush local listing create --json '{"name": "Business"}'

# Map Rank Tracker uses SEMRUSH_OAUTH_TOKEN
semrush local map-rank campaigns
semrush local map-rank keywords <CAMPAIGN_ID>
semrush local map-rank heatmap <CAMPAIGN_ID>
semrush local map-rank heatmap <CAMPAIGN_ID> --keyword-id <KID> --cid <CID>
semrush local map-rank competitors <CAMPAIGN_ID> --keyword-id <KID> --report-date <DATE>
```

### Utility
Expand Down Expand Up @@ -298,8 +302,8 @@ semrush completions <SHELL> # Generate shell completions (bash/zsh/fish)

| Variable | Description |
|----------|-------------|
| `SEMRUSH_API_KEY` | API key (required for v3 endpoints) |
| `SEMRUSH_OAUTH_TOKEN` | OAuth2 token (required for v4 endpoints) |
| `SEMRUSH_API_KEY` | API key for SEO, Trends, Projects, and Listing Management endpoints |
| `SEMRUSH_OAUTH_TOKEN` | OAuth2 bearer token for Map Rank Tracker endpoints |
| `SEMRUSH_DATABASE` | Default regional database |
| `SEMRUSH_OUTPUT` | Default output format |

Expand Down
Loading
Loading