From 81a6e6458ca1c6baf190c2059aadf3c9b9d20d08 Mon Sep 17 00:00:00 2001 From: Mathew Davies Date: Thu, 1 Jun 2023 00:47:58 +0100 Subject: [PATCH] ci: cleanup github actions (#803) --- .github/workflows/docker-arm.yml | 38 ------------ .github/workflows/docker-armv7.yml | 41 ------------ .../workflows/{docker.yml => main-docker.yml} | 34 +++++++--- .github/workflows/{rust.yml => main-rust.yml} | 37 +++++++---- .github/workflows/pull-request.yml | 62 +++++++++++++++++++ .github/workflows/rust-tests.yml | 22 ------- 6 files changed, 111 insertions(+), 123 deletions(-) delete mode 100644 .github/workflows/docker-arm.yml delete mode 100644 .github/workflows/docker-armv7.yml rename .github/workflows/{docker.yml => main-docker.yml} (50%) rename .github/workflows/{rust.yml => main-rust.yml} (56%) create mode 100644 .github/workflows/pull-request.yml delete mode 100644 .github/workflows/rust-tests.yml diff --git a/.github/workflows/docker-arm.yml b/.github/workflows/docker-arm.yml deleted file mode 100644 index 251e325..0000000 --- a/.github/workflows/docker-arm.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Docker ARM Build - -on: - push: - paths-ignore: - - "**.md" - branches: - - master - -jobs: - build-docker: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - with: - platforms: all - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - with: - version: latest - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfile.arm - platforms: linux/arm64 - push: true - tags: libreddit/libreddit:arm - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-armv7.yml b/.github/workflows/docker-armv7.yml deleted file mode 100644 index d2817d8..0000000 --- a/.github/workflows/docker-armv7.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Docker ARM V7 Build - -on: - push: - paths-ignore: - - "**.md" - branches: - - master - -jobs: - build-docker: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up QEMU - id: qemu - uses: docker/setup-qemu-action@v1 - with: - platforms: all - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - with: - version: latest - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push - id: build_push - uses: docker/build-push-action@v2 - with: - context: . - file: ./Dockerfile.armv7 - platforms: linux/arm/v7 - push: true - tags: libreddit/libreddit:armv7 - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/docker.yml b/.github/workflows/main-docker.yml similarity index 50% rename from .github/workflows/docker.yml rename to .github/workflows/main-docker.yml index c90bd4d..9438945 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/main-docker.yml @@ -1,44 +1,58 @@ -name: Docker amd64 Build +name: Docker Build on: push: paths-ignore: - "**.md" branches: - - master + - 'main' + - 'master' jobs: build-docker: runs-on: ubuntu-latest + strategy: + matrix: + config: + - { platform: 'linux/amd64', tag: 'latest', dockerfile: 'Dockerfile' } + - { platform: 'linux/arm64', tag: 'latest-arm', dockerfile: 'Dockerfile.arm' } + - { platform: 'linux/arm/v7', tag: 'latest-armv7', dockerfile: 'Dockerfile.armv7' } steps: - - uses: actions/checkout@v2 + - name: Checkout sources + uses: actions/checkout@v3 + - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + uses: docker/setup-qemu-action@v2 with: platforms: all + - name: Set up Docker Buildx id: buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 with: version: latest + - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Docker Hub Description uses: peter-evans/dockerhub-description@v3 + if: matrix.config.platform == 'linux/amd64' with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} repository: libreddit/libreddit + - name: Build and push - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v4 with: context: . - file: ./Dockerfile - platforms: linux/amd64 + file: ./${{ matrix.config.dockerfile }} + platforms: ${{ matrix.config.platform }} push: true - tags: libreddit/libreddit:latest + tags: libreddit/libreddit:${{ matrix.config.tag }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/rust.yml b/.github/workflows/main-rust.yml similarity index 56% rename from .github/workflows/rust.yml rename to .github/workflows/main-rust.yml index c233140..5089491 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/main-rust.yml @@ -1,33 +1,44 @@ -name: Rust +name: Rust Build & Publish on: push: paths-ignore: - "**.md" + branches: - - master + - 'main' + - 'master' + + release: + types: [published] env: CARGO_TERM_COLOR: always jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Checkout sources + uses: actions/checkout@v3 - name: Cache Packages - uses: Swatinem/rust-cache@v1.0.1 + uses: Swatinem/rust-cache@2 + + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable - name: Build run: cargo build --release - name: Publish to crates.io - continue-on-error: true + if: github.event_name == 'release' run: cargo publish --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }} - - uses: actions/upload-artifact@v2.2.1 + - uses: actions/upload-artifact@v3 name: Upload a Build Artifact with: name: libreddit @@ -35,23 +46,25 @@ jobs: - name: Versions id: version - run: | - echo "::set-output name=version::$(cargo metadata --format-version 1 --no-deps | jq .packages[0].version -r | sed 's/^/v/')" - echo "::set-output name=tag::$(git describe --tags)" + run: echo "VERSION=$(cargo metadata --format-version 1 --no-deps | jq .packages[0].version -r | sed 's/^/v/')" >> "$GITHUB_OUTPUT" - name: Calculate SHA512 checksum run: sha512sum target/release/libreddit > libreddit.sha512 + + - name: Calculate SHA256 checksum + run: sha256sum target/release/libreddit > libreddit.sha256 - name: Release uses: softprops/action-gh-release@v1 if: github.base_ref != 'master' with: - tag_name: ${{ steps.version.outputs.version }} - name: ${{ steps.version.outputs.version }} - ${{ github.event.head_commit.message }} + tag_name: ${{ steps.version.outputs.VERSION }} + name: ${{ steps.version.outputs.VERSION }} - ${{ github.event.head_commit.message }} draft: true files: | target/release/libreddit libreddit.sha512 + libreddit.sha256 body: | - ${{ github.event.head_commit.message }} ${{ github.sha }} generate_release_notes: true diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..5a9491d --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,62 @@ +name: Pull Request + +on: + push: + branches: + - 'main' + - 'master' + + pull_request: + branches: + - 'main' + - 'master' + +jobs: + test: + name: cargo test + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + + - name: Run cargo test + run: cargo test + + format: + name: cargo fmt --all -- --check + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install stable toolchain with rustfmt component + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + components: rustfmt + + - name: Run cargo fmt + run: cargo fmt --all -- --check + + clippy: + name: cargo clippy -- -D warnings + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Install stable toolchain with clippy component + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + components: clippy + + - name: Run cargo clippy + run: cargo clippy -- -D warnings \ No newline at end of file diff --git a/.github/workflows/rust-tests.yml b/.github/workflows/rust-tests.yml deleted file mode 100644 index c93aadf..0000000 --- a/.github/workflows/rust-tests.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Tests - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose