瀏覽代碼

ci: cleanup github actions (#803)

Mathew Davies 2 年之前
父節點
當前提交
81a6e6458c

+ 0 - 38
.github/workflows/docker-arm.yml

@@ -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

+ 0 - 41
.github/workflows/docker-armv7.yml

@@ -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

+ 24 - 10
.github/workflows/docker.yml → .github/workflows/main-docker.yml

@@ -1,44 +1,58 @@
-name: Docker amd64 Build
+name: Docker Build
 
 
 on:
 on:
   push:
   push:
     paths-ignore:
     paths-ignore:
       - "**.md"
       - "**.md"
     branches:
     branches:
-      - master
+      - 'main'
+      - 'master'
 
 
 jobs:
 jobs:
   build-docker:
   build-docker:
     runs-on: ubuntu-latest
     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:
     steps:
-      - uses: actions/checkout@v2
+      - name: Checkout sources
+        uses: actions/checkout@v3
+
       - name: Set up QEMU
       - name: Set up QEMU
-        uses: docker/setup-qemu-action@v1
+        uses: docker/setup-qemu-action@v2
         with:
         with:
           platforms: all
           platforms: all
+
       - name: Set up Docker Buildx
       - name: Set up Docker Buildx
         id: buildx
         id: buildx
-        uses: docker/setup-buildx-action@v1
+        uses: docker/setup-buildx-action@v2
         with:
         with:
           version: latest
           version: latest
+
       - name: Login to DockerHub
       - name: Login to DockerHub
-        uses: docker/login-action@v1
+        uses: docker/login-action@v2
         with:
         with:
           username: ${{ secrets.DOCKER_USERNAME }}
           username: ${{ secrets.DOCKER_USERNAME }}
           password: ${{ secrets.DOCKER_PASSWORD }}
           password: ${{ secrets.DOCKER_PASSWORD }}
+
       - name: Docker Hub Description
       - name: Docker Hub Description
         uses: peter-evans/dockerhub-description@v3
         uses: peter-evans/dockerhub-description@v3
+        if: matrix.config.platform == 'linux/amd64'
         with:
         with:
           username: ${{ secrets.DOCKER_USERNAME }}
           username: ${{ secrets.DOCKER_USERNAME }}
           password: ${{ secrets.DOCKER_PASSWORD }}
           password: ${{ secrets.DOCKER_PASSWORD }}
           repository: libreddit/libreddit
           repository: libreddit/libreddit
+
       - name: Build and push
       - name: Build and push
-        uses: docker/build-push-action@v2
+        uses: docker/build-push-action@v4
         with:
         with:
           context: .
           context: .
-          file: ./Dockerfile
-          platforms: linux/amd64
+          file: ./${{ matrix.config.dockerfile }}
+          platforms: ${{ matrix.config.platform }}
           push: true
           push: true
-          tags: libreddit/libreddit:latest
+          tags: libreddit/libreddit:${{ matrix.config.tag }}
           cache-from: type=gha
           cache-from: type=gha
           cache-to: type=gha,mode=max
           cache-to: type=gha,mode=max

+ 25 - 12
.github/workflows/rust.yml → .github/workflows/main-rust.yml

@@ -1,33 +1,44 @@
-name: Rust
+name: Rust Build & Publish
 
 
 on:
 on:
   push:
   push:
     paths-ignore:
     paths-ignore:
       - "**.md"
       - "**.md"
+  
     branches:
     branches:
-      - master
+      - 'main'
+      - 'master'
+  
+  release:
+    types: [published]
 
 
 env:
 env:
   CARGO_TERM_COLOR: always
   CARGO_TERM_COLOR: always
 
 
 jobs:
 jobs:
   build:
   build:
-    runs-on: ubuntu-18.04
+    runs-on: ubuntu-latest
 
 
     steps:
     steps:
-      - uses: actions/checkout@v2
+      - name: Checkout sources
+        uses: actions/checkout@v3
 
 
       - name: Cache Packages
       - 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
       - name: Build
         run: cargo build --release
         run: cargo build --release
 
 
       - name: Publish to crates.io
       - name: Publish to crates.io
-        continue-on-error: true
+        if: github.event_name == 'release'
         run: cargo publish --no-verify --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
         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
         name: Upload a Build Artifact
         with:
         with:
           name: libreddit
           name: libreddit
@@ -35,23 +46,25 @@ jobs:
         
         
       - name: Versions
       - name: Versions
         id: version
         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
       - name: Calculate SHA512 checksum
         run: sha512sum target/release/libreddit > libreddit.sha512
         run: sha512sum target/release/libreddit > libreddit.sha512
+
+      - name: Calculate SHA256 checksum
+        run: sha256sum target/release/libreddit > libreddit.sha256
         
         
       - name: Release
       - name: Release
         uses: softprops/action-gh-release@v1
         uses: softprops/action-gh-release@v1
         if: github.base_ref != 'master'
         if: github.base_ref != 'master'
         with:
         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
           draft: true
           files: |
           files: |
             target/release/libreddit
             target/release/libreddit
             libreddit.sha512
             libreddit.sha512
+            libreddit.sha256
           body: |
           body: |
             - ${{ github.event.head_commit.message }} ${{ github.sha }}
             - ${{ github.event.head_commit.message }} ${{ github.sha }}
           generate_release_notes: true
           generate_release_notes: true

+ 62 - 0
.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

+ 0 - 22
.github/workflows/rust-tests.yml

@@ -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