This repository was archived by the owner on Sep 30, 2025. It is now read-only.
Publish #7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| on: | |
| workflow_dispatch: | |
| push: | |
| tags: ["v*"] | |
| jobs: | |
| publish-package: | |
| name: Publish Package | |
| environment: protected | |
| permissions: | |
| contents: read | |
| id-token: write | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
| - name: Setup Python | |
| uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b | |
| with: | |
| python-version: "3.11" | |
| - name: Install Poetry | |
| uses: abatilo/actions-poetry@e78f54a89cb052fff327414dd9ff010b5d2b4dbd | |
| with: | |
| poetry-version: "1.8.4" | |
| - name: Configure Poetry | |
| run: | | |
| poetry config virtualenvs.create true --local | |
| poetry config virtualenvs.in-project true --local | |
| - name: Install package | |
| run: poetry install --no-dev | |
| - name: Validate version | |
| run: | | |
| TAG_VERSION=${GITHUB_REF#refs/tags/v} | |
| POETRY_VERSION=$(poetry version -s) | |
| INIT_VERSION=$(python -c "import dreadnode_cli; print(dreadnode_cli.__version__)") | |
| if ! [[ $TAG_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "Invalid tag format: $TAG_VERSION. Must be vX.X.X" | |
| exit 1 | |
| fi | |
| if [ "$POETRY_VERSION" != "$INIT_VERSION" ]; then | |
| echo "Version mismatch: pyproject.toml ($POETRY_VERSION) != __init__.py ($INIT_VERSION)" | |
| exit 1 | |
| fi | |
| if [ "$TAG_VERSION" != "$POETRY_VERSION" ]; then | |
| echo "Tag ($TAG_VERSION) doesn't match pyproject.toml ($POETRY_VERSION)" | |
| exit 1 | |
| fi | |
| - name: Build package | |
| run: | | |
| poetry build | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@15c56dba361d8335944d31a2ecd17d700fc7bcbc | |
| publish-docker: | |
| name: Publish Docker | |
| environment: protected | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | |
| - name: Setup QEMU | |
| uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@c47758b77c9736f4b2ef4073d4d51994fabfe349 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Set Docker tags | |
| id: tags | |
| run: | | |
| VERSION=${GITHUB_REF#refs/tags/v} | |
| echo "tags=dreadnode/cli:latest,dreadnode/cli:$VERSION" >> $GITHUB_OUTPUT | |
| - name: Build and push | |
| uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: ${{ steps.tags.outputs.tags }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |