Skip to content

Commit

Permalink
chore(ci): use docker
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp committed Jan 12, 2024
1 parent c67ca46 commit 48798a9
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 177 deletions.
153 changes: 6 additions & 147 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ name: Setup
description: Setup CI environment.

inputs:
type:
description: Type of setup, `minimal` will only setup the JavaScript monorepo, empty will also install Java.
required: false
language:
description: the language for which to install deps
javascript-utils:
description: If true, it will also restore the cache of the javascript util packages.
required: false

runs:
Expand All @@ -18,31 +15,7 @@ runs:
run: |
echo "CACHE_VERSION=$(< .github/.cache_version)" >> $GITHUB_ENV
# Java for code generation
- name: Install Java
if: inputs.type != 'minimal'
uses: actions/setup-java@v4
with:
distribution: zulu
java-version-file: config/.java-version
cache: gradle

- name: Validate gradle wrapper
if: inputs.type != 'minimal'
uses: gradle/wrapper-validation-action@v1

- name: Download Java formatter
if: inputs.type != 'minimal'
shell: bash
run: curl --retry 3 -L "https://github.com/google/google-java-format/releases/download/v1.19.2/google-java-format-1.19.2-all-deps.jar" > /tmp/java-formatter.jar

# JavaScript for monorepo and tooling
- name: Install Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: yarn

- name: Get yarn cache directory path
shell: bash
id: yarn-cache-dir
Expand All @@ -69,143 +42,29 @@ runs:
shell: bash
run: yarn workspace scripts build:cli

- name: Get all languages versions
id: versions
shell: bash
run: |
# remove patch from php version
echo "CSHARP_VERSION=$(cat config/.csharp-version)" >> $GITHUB_OUTPUT
echo "DART_VERSION=$(cat config/.dart-version)" >> $GITHUB_OUTPUT
echo "GO_VERSION=$(cat config/.go-version)" >> $GITHUB_OUTPUT
echo "PHP_VERSION=$(cat config/.php-version | cut -d '.' -f 1,2)" >> $GITHUB_OUTPUT
echo "PYTHON_VERSION=$(cat config/.python-version)" >> $GITHUB_OUTPUT
echo "RUBY_VERSION=$(cat config/.ruby-version)" >> $GITHUB_OUTPUT
echo "SWIFT_VERSION=$(cat config/.swift-version)" >> $GITHUB_OUTPUT
# JavaScript client deps
- name: Get yarn js-client cache directory path
if: ${{ inputs.language == 'javascript' }}
if: ${{ inputs.javascript-utils == 'true' }}
shell: bash
id: yarn-cache-dir-client
run: echo "dir=$(cd clients/algoliasearch-client-javascript && yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- name: Restore Yarn js-client
if: ${{ inputs.language == 'javascript' }}
if: ${{ inputs.javascript-utils == 'true' }}
uses: actions/cache@v3
with:
path: ${{ steps.yarn-cache-dir-client.outputs.dir || 'clients/algoliasearch-client-javascript/.yarn/cache' }}
# let yarn handle the cache hash
key: yarn-cache-client-${{ env.CACHE_VERSION }}

- name: Cache js-client node modules
if: ${{ inputs.language == 'javascript' }}
if: ${{ inputs.javascript-utils == 'true' }}
uses: actions/cache@v3
with:
path: clients/algoliasearch-client-javascript/node_modules
key: node-modules-client-${{ env.CACHE_VERSION }}-${{ hashFiles('clients/algoliasearch-client-javascript/yarn.lock') }}

- name: Install JavaScript client dependencies
if: ${{ inputs.language == 'javascript' }}
if: ${{ inputs.javascript-utils == 'true' }}
shell: bash
run: cd clients/algoliasearch-client-javascript && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install

# PHP
- name: Install PHP
if: ${{ inputs.language == 'php' }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ steps.versions.outputs.PHP_VERSION }}
tools: composer

- name: Run composer install
if: ${{ inputs.language == 'php' }}
shell: bash
run: |
composer install --working-dir=clients/algoliasearch-client-php
composer dump-autoload --working-dir=clients/algoliasearch-client-php
# Golang
- name: Install golang
if: ${{ inputs.language == 'go' }}
uses: actions/setup-go@v5
with:
cache-dependency-path: clients/algoliasearch-client-go/go.sum
go-version: ${{ steps.versions.outputs.GO_VERSION }}

- name: Install golangci-lint
if: ${{ inputs.language == 'go' }}
shell: bash
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.2
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
go install golang.org/x/tools/cmd/goimports@latest
# Dart
- name: Install dart
if: ${{ inputs.language == 'dart' }}
uses: dart-lang/setup-dart@v1
with:
sdk: ${{ steps.versions.outputs.DART_VERSION }}

- name: Setup dart tools
if: ${{ inputs.language == 'dart' }}
shell: bash
run: dart pub global activate melos

# Python
- name: Install poetry
if: ${{ inputs.language == 'python' }}
shell: bash
run: pipx install poetry

- uses: actions/setup-python@v5
if: ${{ inputs.language == 'python' }}
with:
python-version: ${{ steps.versions.outputs.PYTHON_VERSION }}
cache: 'poetry'

- run: poetry install
if: ${{ inputs.language == 'python' }}
working-directory: clients/algoliasearch-client-python
shell: bash

# Ruby
- name: Install Ruby
if: ${{ inputs.language == 'ruby' }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ steps.versions.outputs.RUBY_VERSION }}
bundler-cache: true

# Csharp
- name: Install dotnet
if: ${{ inputs.language == 'csharp' }}
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ steps.versions.outputs.CSHARP_VERSION }}

# Swift deps
- name: Install swift
if: ${{ inputs.language == 'swift' }}
uses: swift-actions/setup-swift@v1
with:
swift-version: ${{ steps.versions.outputs.SWIFT_VERSION }}

- name: Set up Homebrew
if: ${{ inputs.language == 'swift' }}
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Cache Homebrew Bundler RubyGems
if: ${{ inputs.language == 'swift' }}
id: cache
uses: actions/cache@v3
with:
path: ${{ steps.set-up-homebrew.outputs.gems-path }}
key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
restore-keys: ${{ runner.os }}-rubygems-

- name: Install swift-format
if: ${{ inputs.language == 'swift' && steps.cache.outputs.cache-hit != 'true' }}
shell: bash
run: brew install swift-format
39 changes: 27 additions & 12 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ concurrency:
jobs:
setup:
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic_base
volumes: [./:/app]
timeout-minutes: 10
steps:
- name: debugging - dump GitHub context
Expand All @@ -35,6 +38,9 @@ jobs:
id: setup
uses: ./.github/actions/setup

- name: Validate gradle wrapper
uses: gradle/wrapper-validation-action@v1

# Computing jobs that should run
- name: Setting diff outputs variables
id: diff
Expand Down Expand Up @@ -98,6 +104,9 @@ jobs:

scripts:
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic_base
volumes: [./:/app]
timeout-minutes: 10
needs: setup
if: ${{ needs.setup.outputs.RUN_SCRIPTS == 'true' }}
Expand All @@ -106,8 +115,6 @@ jobs:

- name: Setup
uses: ./.github/actions/setup
with:
type: minimal

- name: Check script linting
run: yarn scripts:lint
Expand All @@ -120,6 +127,9 @@ jobs:

specs:
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic_base
volumes: [./:/app]
timeout-minutes: 10
needs: setup
steps:
Expand All @@ -135,8 +145,6 @@ jobs:
- name: Setup
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: ./.github/actions/setup
with:
type: minimal

- name: Building specs
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
Expand All @@ -152,6 +160,9 @@ jobs:
client_javascript_utils:
timeout-minutes: 10
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic_base
volumes: [./:/app]
needs: setup
if: ${{ needs.setup.outputs.RUN_GEN_JAVASCRIPT == 'true' }}
strategy:
Expand Down Expand Up @@ -184,8 +195,7 @@ jobs:
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: ./.github/actions/setup
with:
type: minimal
language: javascript
javascript-utils: true

- name: Build '${{ matrix.client }}' client
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
Expand All @@ -198,6 +208,9 @@ jobs:
client_gen_javascript:
timeout-minutes: 10
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic_base
volumes: [./:/app]
needs:
- setup
- client_javascript_utils
Expand Down Expand Up @@ -239,7 +252,7 @@ jobs:
- name: Setup
uses: ./.github/actions/setup
with:
language: javascript
javascript-utils: true

- name: Generate clients
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
Expand Down Expand Up @@ -303,7 +316,10 @@ jobs:

client_gen:
timeout-minutes: 20
runs-on: ${{ matrix.client.language == 'swift' && 'macos-12' || 'ubuntu-22.04' }}
runs-on: 'ubuntu-22.04'
container:
image: ${{ format('ghcr.io/algolia/{0}', matrix.client.dockerImage }}
volumes: [./:/app]
needs:
- setup
- specs
Expand Down Expand Up @@ -337,8 +353,6 @@ jobs:

- name: Setup
uses: ./.github/actions/setup
with:
language: ${{ matrix.client.language }}

- name: Generate clients
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
Expand Down Expand Up @@ -384,6 +398,9 @@ jobs:

codegen:
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic_base
volumes: [./:/app]
timeout-minutes: 10
needs:
- setup
Expand All @@ -408,8 +425,6 @@ jobs:

- name: Setup
uses: ./.github/actions/setup
with:
type: minimal

- name: Push generated code
id: pushGeneratedCode
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
jobs:
notification:
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic_base
volumes: [./:/app]
timeout-minutes: 10
if: (github.event.action == 'opened' || github.event.action == 'synchronize') && github.event.number
steps:
Expand All @@ -17,8 +20,6 @@ jobs:

- name: Setup
uses: ./.github/actions/setup
with:
type: minimal

- name: Add notification comment
run: yarn workspace scripts upsertGenerationComment notification
Expand All @@ -29,6 +30,9 @@ jobs:

cleanup:
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic_base
volumes: [./:/app]
timeout-minutes: 10
if: github.event.action == 'closed'
steps:
Expand All @@ -39,8 +43,6 @@ jobs:

- name: Setup
uses: ./.github/actions/setup
with:
type: minimal

- name: Add cleanup comment
run: yarn workspace scripts upsertGenerationComment cleanup
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/scheduled-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ jobs:
- name: Setup
id: setup
uses: ./.github/actions/setup
with:
type: minimal
language: dart # we need the dart deps because we use melos to bump dependencies for its client

- run: yarn release
env:
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci/githubActions/createMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as core from '@actions/core';
import { CLIENTS, createClientName, GENERATORS, LANGUAGES } from '../../common.js';
import {
getClientsConfigField,
getDockerImage,
getLanguageFolder,
getTestExtension,
getTestOutputFolder,
Expand Down Expand Up @@ -142,6 +143,7 @@ async function createClientMatrix(baseBranch: string): Promise<void> {
testsToDelete,
testsToStore,
snippetsToStore,
dockerImage: getDockerImage(language),
});
}

Expand Down
Loading

0 comments on commit 48798a9

Please sign in to comment.