From 976d87564e52773b9708826c7718d4247c7b254c Mon Sep 17 00:00:00 2001
From: Kirill Fomichev <fanatid@ya.ru>
Date: Fri, 7 Jun 2024 21:01:33 -0400
Subject: [PATCH] ci: update actions (#78)

---
 .github/workflows/release.yml | 50 +++++++++++++--------------
 .github/workflows/test.yml    | 63 ++++++++++++++++++-----------------
 ci/rust-version.sh            |  0
 rustfmt.toml                  |  3 ++
 4 files changed, 61 insertions(+), 55 deletions(-)
 mode change 100755 => 100644 ci/rust-version.sh
 create mode 100644 rustfmt.toml

diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 11c362c..809a1cc 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1,18 +1,22 @@
-name: Release plugin
+permissions:
+  contents: write
 
 concurrency:
   group: ${{ github.workflow }}-${{ github.ref }}
   cancel-in-progress: true
 
 on:
-  push:
-    tags:
-      - 'v*'
-    branches:
-      - 'master'
   pull_request:
     paths:
       - '.github/workflows/release.yml'
+  push:
+    branches:
+      - 'master'
+      - 'v1.16'
+      - 'v1.17'
+    tags:
+      - 'v*'
+  workflow_dispatch:
 
 env:
   CARGO_TERM_COLOR: always
@@ -23,13 +27,14 @@ jobs:
       matrix:
         os: [ubuntu-20.04, ubuntu-22.04]
     runs-on: ["${{ matrix.os }}"]
+
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
 
       - name: Set rust version
         run: |
-          source ci/rust-version.sh
-          echo "RUST_STABLE=$rust_stable" | tee -a $GITHUB_ENV
+          RUST_VERSION="$(grep -oP 'channel = "\K\d\.\d+\.\d+(?=")' rust-toolchain.toml)"
+          echo "RUST_VERSION=$RUST_VERSION" >> "$GITHUB_ENV"
 
       - name: Set env vars
         run: |
@@ -42,22 +47,17 @@ jobs:
           sudo apt-get update
           sudo apt-get install -y libudev-dev libssl-dev libsasl2-dev libzstd-dev
 
-      - uses: actions-rs/toolchain@v1
-        with:
-          toolchain: ${{ env.RUST_STABLE }}
-          override: true
-          profile: minimal
-          components: rustfmt
-
-      - uses: actions/cache@v3
+      - uses: actions/cache@v4
         with:
           path: |
-              ~/.cargo/bin/
-              ~/.cargo/registry/index/
-              ~/.cargo/registry/cache/
-              ~/.cargo/git/db/
-              target
-          key: ${{ matrix.os }}-cargo-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('Cargo.lock') }}-0001
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+            ./target
+          key: cargo-${{ matrix.os }}-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('**/Cargo.lock') }}-0000
+          restore-keys: |
+            cargo-${{ matrix.os }}-${{ hashFiles('rust-toolchain.toml') }}
 
       - name: Check Solana version
         run: |
@@ -89,13 +89,13 @@ jobs:
 
       - name: Release
         if: startsWith(github.ref, 'refs/tags/')
-        uses: softprops/action-gh-release@v1
+        uses: softprops/action-gh-release@v2
         with:
           tag_name: ${{ env.BUILD_NAME }}
           body: |
             ${{ env.GEYSER_PLUGIN_NAME }} ${{ env.CI_TAG }}
             solana ${{ env.SOLANA_VERSION }}
-            rust ${{ env.RUST_STABLE }}
+            rust ${{ env.RUST_VERSION }}
           files: |
             ${{ env.GEYSER_PLUGIN_NAME }}-release*
             target/release/config*
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 06ab07b..61a7c6c 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -1,15 +1,18 @@
 # Source:
 # https://github.com/solana-labs/solana-accountsdb-plugin-postgres/blob/master/.github/workflows/test.yml
 
-name: Build plugin
-
 concurrency:
   group: ${{ github.workflow }}-${{ github.ref }}
   cancel-in-progress: true
 
 on:
-  workflow_dispatch:
   pull_request:
+  push:
+    branches:
+      - 'master'
+      - 'v1.16'
+      - 'v1.17'
+  workflow_dispatch:
 
 env:
   CARGO_TERM_COLOR: always
@@ -20,13 +23,14 @@ jobs:
       matrix:
         os: [ubuntu-20.04, ubuntu-22.04]
     runs-on: ["${{ matrix.os }}"]
+
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
 
       - name: Set rust version
         run: |
-          source ci/rust-version.sh
-          echo "RUST_STABLE=$rust_stable" | tee -a $GITHUB_ENV
+          RUST_VERSION="$(grep -oP 'channel = "\K\d\.\d+\.\d+(?=")' rust-toolchain.toml)"
+          echo "RUST_VERSION=$RUST_VERSION" >> "$GITHUB_ENV"
 
       - name: Set env vars
         run: |
@@ -39,40 +43,39 @@ jobs:
           sudo apt-get update
           sudo apt-get install -y libudev-dev libssl-dev libsasl2-dev libzstd-dev
 
-      - uses: actions-rs/toolchain@v1
+      - uses: actions/cache@v4
+        with:
+          path: |
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+            ./target
+          key: cargo-${{ matrix.os }}-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('**/Cargo.lock') }}-0000
+          restore-keys: |
+            cargo-${{ matrix.os }}-${{ hashFiles('rust-toolchain.toml') }}
+
+      - uses: dtolnay/rust-toolchain@stable
         with:
-          toolchain: ${{ env.RUST_STABLE }}
-          override: true
-          profile: minimal
-          components: rustfmt, clippy
+          toolchain: nightly
+          components: rustfmt
 
-      - uses: actions/cache@v3
+      - uses: dtolnay/rust-toolchain@stable
         with:
-          path: |
-              ~/.cargo/bin/
-              ~/.cargo/registry/index/
-              ~/.cargo/registry/cache/
-              ~/.cargo/git/db/
-              target
-          key: ${{ matrix.os }}-cargo-${{ hashFiles('rust-toolchain.toml') }}-${{ hashFiles('Cargo.lock') }}-0001
+          toolchain: ${{ env.RUST_VERSION }}
+          components: clippy
 
       - name: cargo tree
         run: |
           cargo tree
           git checkout Cargo.lock
-          cargo tree --frozen
+          cargo tree --frozen --offline
 
-      - name: cargo fmt
-        uses: actions-rs/cargo@v1
-        with:
-          command: fmt
-          args: --all -- --check
+      - name: Run fmt
+        run: cargo +nightly fmt --all -- --check
 
-      - name: cargo clippy
-        uses: actions-rs/cargo@v1
-        with:
-          command: clippy
-          args: --workspace --all-targets --tests #-- --deny=warnings
+      - name: Run clippy
+        run: cargo clippy --all-targets --tests -- -Dwarnings
 
       - name: Build
         run: ./ci/cargo-build-test.sh
diff --git a/ci/rust-version.sh b/ci/rust-version.sh
old mode 100755
new mode 100644
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..fe957b9
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1,3 @@
+edition = "2021"
+imports_granularity = "One"
+group_imports = "One"