diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..50ba703 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,36 @@ +name: Build and Push Docker Image + +on: + workflow_run: + workflows: ["Rust lint, build and test"] + types: + - completed + +jobs: + build-and-push: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Extract version + id: cargo-version + run: | + VERSION=$(grep '^version' Cargo.toml | head -n 1 | awk -F'"' '{print $2}') + echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "Version extracted: $VERSION" + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build image + run: docker build -t docker.io/uhryniuk/tally:${{ env.VERSION }} . + + - name: Push image + run: docker push docker.io/uhryniuk/tally:${{ env.VERSION }} + diff --git a/.github/workflows/lint-build-test.yml b/.github/workflows/lint-build-test.yml index fa6f413..783f9ab 100644 --- a/.github/workflows/lint-build-test.yml +++ b/.github/workflows/lint-build-test.yml @@ -1,4 +1,4 @@ -name: Rust +name: Rust lint, build and test on: push: @@ -14,11 +14,9 @@ jobs: runs-on: ubuntu-latest steps: - # Checkout the code - name: Checkout code uses: actions/checkout@v3 - # Install a specific version of Rust (e.g., 1.68.0) - name: Set up Rust uses: actions-rs/toolchain@v1 with: @@ -26,33 +24,26 @@ jobs: profile: minimal override: true - # Install rustfmt, clippy, and other components - name: Install rustfmt, clippy, and audit run: | rustup component add rustfmt clippy cargo install cargo-audit - # Run rustfmt to check code formatting - name: Check formatting with rustfmt run: cargo fmt -- --check - # Run clippy to check for linting issues - name: Run Clippy for linting run: cargo clippy -- -D warnings - # Run cargo audit to check for security vulnerabilities - name: Run cargo audit for security vulnerabilities run: cargo audit - # Build the project - name: Build project run: cargo build --release - # Run the tests - name: Run tests run: cargo test - # Check if version has been incremented - name: Ensure version has been incremented run: | VERSION_BASE=$(git show origin/main:Cargo.toml | grep '^version = ' | awk '{ print $3 }' | tr -d '"')