From 0ac534ce9909fc081f0bc1c4171be369dda59250 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Thu, 5 Jan 2023 09:19:32 +0100 Subject: [PATCH] GitHub: extract common steps --- .github/actions/setup-go/action.yml | 32 +++++ .github/actions/setup-node/action.yml | 37 +++++ .github/workflows/main.yml | 188 ++++++-------------------- 3 files changed, 110 insertions(+), 147 deletions(-) create mode 100644 .github/actions/setup-go/action.yml create mode 100644 .github/actions/setup-node/action.yml diff --git a/.github/actions/setup-go/action.yml b/.github/actions/setup-go/action.yml new file mode 100644 index 000000000..4571a9359 --- /dev/null +++ b/.github/actions/setup-go/action.yml @@ -0,0 +1,32 @@ +name: "Setup Golang environment" +description: "A reusable workflow that's used to set up the Go environment and cache." +inputs: + go-version: + description: "The version of Golang to set up" + required: true + +runs: + using: "composite" + + steps: + - name: set git config + shell: bash + run: | + git config --global core.eol lf + git config --global core.autocrlf false + + - name: setup go ${{ inputs.go-version }} + uses: actions/setup-go@v3 + with: + go-version: '${{ inputs.go-version }}' + + - name: go cache + uses: actions/cache@v3 + with: + path: /home/runner/work/go + key: litd-${{ runner.os }}-go-${{ inputs.go-version }}-${{ github.job }}-${{ hashFiles('**/go.sum') }} + restore-keys: | + litd-${{ runner.os }}-go-${{ inputs.go-version }}-${{ github.job }}-${{ hashFiles('**/go.sum') }} + litd-${{ runner.os }}-go-${{ inputs.go-version }}-${{ github.job }}- + litd-${{ runner.os }}-go-${{ inputs.go-version }}- + litd-${{ runner.os }}-go- diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml new file mode 100644 index 000000000..c272b08f4 --- /dev/null +++ b/.github/actions/setup-node/action.yml @@ -0,0 +1,37 @@ +name: "Setup Node environment" +description: "A reusable workflow that's used to set up the Node environment and cache." +inputs: + node-version: + description: "The version of Node to set up" + required: true + +runs: + using: "composite" + + steps: + - name: set git config + shell: bash + run: | + git config --global core.eol lf + git config --global core.autocrlf false + + - name: setup nodejs v${{ inputs.node-version }} + uses: actions/setup-node@v1 + with: + node-version: '${{ inputs.node-version }}' + + - name: get yarn cache dir + id: yarn-cache-dir + shell: bash + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: yarn cache + uses: actions/cache@v2 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir.outputs.dir }} + key: litd-${{ runner.os }}-yarn-${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + litd-${{ runner.os }}-yarn-${{ inputs.node-version }}-${{ hashFiles('**/yarn.lock') }} + litd-${{ runner.os }}-yarn-${{ inputs.node-version }}- + litd-${{ runner.os }}-yarn- diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bcd383194..c53592f4c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,33 +31,15 @@ jobs: os: [ubuntu-latest, windows-latest, macOS-latest] steps: - - name: set git config - run: | - git config --global core.eol lf - git config --global core.autocrlf false - - name: git checkout - uses: actions/checkout@v2 - - - name: setup nodejs v${{ matrix.node_version }} - uses: actions/setup-node@v1 + uses: actions/checkout@v3 with: - node-version: ${{ matrix.node_version }} - - - name: get yarn cache dir - id: yarn-cache-dir - run: echo "::set-output name=dir::$(yarn cache dir)" + fetch-depth: 0 - - name: yarn cache - uses: actions/cache@v2 - id: yarn-cache + - name: setup nodejs ${{ matrix.node_version }} + uses: ./.github/actions/setup-node with: - path: ${{ steps.yarn-cache-dir.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }} - ${{ runner.os }}-yarn-${{ matrix.node_version }}- - ${{ runner.os }}-yarn- + node-version: '${{ matrix.node_version }}' - name: install dependencies working-directory: ./app @@ -88,43 +70,20 @@ jobs: os: [ubuntu-latest, windows-latest, macOS-latest] steps: - - name: Set git to use LF - run: | - git config --global core.eol lf - git config --global core.autocrlf false - - name: git checkout - uses: actions/checkout@v2 - - - name: go cache - uses: actions/cache@v2 + uses: actions/checkout@v3 with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ matrix.go_version }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go-${{ matrix.go_version }}-${{ hashFiles('**/go.sum') }} - ${{ runner.os }}-go-${{ matrix.go_version }}- - ${{ runner.os }}-go- - - - name: get yarn cache dir - id: yarn-cache-dir - run: echo "::set-output name=dir::$(yarn cache dir)" - - - name: yarn cache - uses: actions/cache@v2 - id: yarn-cache + fetch-depth: 0 + + - name: setup nodejs ${{ matrix.node_version }} + uses: ./.github/actions/setup-node with: - path: ${{ steps.yarn-cache-dir.outputs.dir }} - key: ${{ runner.os }}-yarn-16.x-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn-16.x-${{ hashFiles('**/yarn.lock') }} - ${{ runner.os }}-yarn-16.x- - ${{ runner.os }}-yarn- - - - name: setup go v${{ matrix.go_version }} - uses: actions/setup-go@v2 + node-version: '${{ matrix.node_version }}' + + - name: setup go ${{ env.GO_VERSION }} + uses: ./.github/actions/setup-go with: - go-version: '~${{ matrix.go_version }}' + go-version: '${{ env.GO_VERSION }}' - name: build backend binary run: make build @@ -139,52 +98,25 @@ jobs: name: RPC proto compilation check runs-on: ubuntu-latest steps: - - name: set git config - run: | - git config --global core.eol lf - git config --global core.autocrlf false - - name: git checkout - uses: actions/checkout@v2 - - - name: setup nodejs v16.x - uses: actions/setup-node@v1 + uses: actions/checkout@v3 with: - node-version: 16.x + fetch-depth: 0 - - name: download cache - uses: actions/cache@v1 + - name: setup nodejs ${{ matrix.node_version }} + uses: ./.github/actions/setup-node with: - path: /home/runner/work/download_cache - key: litd-${{ runner.os }}-download-${{ hashFiles('**/install_protoc.sh') }} - restore-keys: | - litd-${{ runner.os }}-download-${{ hashFiles('**/install_protoc.sh') }} - litd-${{ runner.os }}-download- - - - name: get yarn cache dir - id: yarn-cache-dir - run: echo "::set-output name=dir::$(yarn cache dir)" - - - name: yarn cache - uses: actions/cache@v2 - id: yarn-cache + node-version: '${{ matrix.node_version }}' + + - name: setup go ${{ env.GO_VERSION }} + uses: ./.github/actions/setup-go with: - path: ${{ steps.yarn-cache-dir.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }} - ${{ runner.os }}-yarn-${{ matrix.node_version }}- - ${{ runner.os }}-yarn- + go-version: '${{ env.GO_VERSION }}' - name: install dependencies working-directory: ./app run: yarn - - name: setup go ${{ env.GO_VERSION }} - uses: actions/setup-go@v2 - with: - go-version: '${{ env.GO_VERSION }}' - - name: compile rpc for golang run: make rpc @@ -200,23 +132,12 @@ jobs: runs-on: ubuntu-latest steps: - name: git checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - - name: go cache - uses: actions/cache@v1 - with: - path: /home/runner/work/go - key: litd-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - litd-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }} - litd-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}- - litd-${{ runner.os }}-go-${{ env.GO_VERSION }}- - litd-${{ runner.os }}-go- - - name: setup go ${{ env.GO_VERSION }} - uses: actions/setup-go@v2 + uses: ./.github/actions/setup-go with: go-version: '${{ env.GO_VERSION }}' @@ -239,12 +160,12 @@ jobs: runs-on: ubuntu-latest steps: - name: git checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: setup go ${{ env.GO_VERSION }} - uses: actions/setup-go@v2 + uses: ./.github/actions/setup-go with: go-version: '${{ env.GO_VERSION }}' @@ -262,12 +183,12 @@ jobs: runs-on: ubuntu-latest steps: - name: git checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: setup go ${{ env.GO_VERSION }} - uses: actions/setup-go@v2 + uses: ./.github/actions/setup-go with: go-version: '${{ env.GO_VERSION }}' @@ -282,12 +203,12 @@ jobs: runs-on: ubuntu-latest steps: - name: git checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: setup go ${{ env.GO_VERSION }} - uses: actions/setup-go@v2 + uses: ./.github/actions/setup-go with: go-version: '${{ env.GO_VERSION }}' @@ -301,51 +222,24 @@ jobs: name: integration test runs-on: ubuntu-latest steps: - - name: set git config - run: | - git config --global core.eol lf - git config --global core.autocrlf false - - name: git checkout - uses: actions/checkout@v2 - - - name: setup nodejs v${{ matrix.node_version }} - uses: actions/setup-node@v1 + uses: actions/checkout@v3 with: - node-version: 16.x + fetch-depth: 0 - - name: download cache - uses: actions/cache@v1 + - name: setup nodejs ${{ matrix.node_version }} + uses: ./.github/actions/setup-node with: - path: /home/runner/work/download_cache - key: litd-${{ runner.os }}-download-${{ hashFiles('**/install_protoc.sh') }} - restore-keys: | - litd-${{ runner.os }}-download-${{ hashFiles('**/install_protoc.sh') }} - litd-${{ runner.os }}-download- - - - name: get yarn cache dir - id: yarn-cache-dir - run: echo "::set-output name=dir::$(yarn cache dir)" - - - name: yarn cache - uses: actions/cache@v2 - id: yarn-cache + node-version: '${{ matrix.node_version }}' + + - name: setup go ${{ env.GO_VERSION }} + uses: ./.github/actions/setup-go with: - path: ${{ steps.yarn-cache-dir.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }} - ${{ runner.os }}-yarn-${{ matrix.node_version }}- - ${{ runner.os }}-yarn- + go-version: '${{ env.GO_VERSION }}' - name: install dependencies working-directory: ./app run: yarn - - name: setup go ${{ env.GO_VERSION }} - uses: actions/setup-go@v2 - with: - go-version: '${{ env.GO_VERSION }}' - - name: run check run: make itest