Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ci): use docker #2525

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 17 additions & 148 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name: Setup
description: Setup CI environment.

inputs:
type:
description: Type of setup, `minimal` will only setup the JavaScript monorepo, empty will also install Java.
install-node:
description: If true, it will install the node with the version from .nvmrc.
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,26 +18,19 @@ 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'
- name: Edit config for docker
if: ${{ inputs.install-node != 'true' }}
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
run: |
source /root/.profile
echo "setting PATH: $PATH"
echo "$PATH" >> $GITHUB_PATH
echo "/root/.nvm/versions/node/$(cat .nvmrc)/bin" >> $GITHUB_PATH
git config --global --add safe.directory /__w/api-clients-automation/api-clients-automation

# JavaScript for monorepo and tooling
- name: Install Node
if: ${{ inputs.install-node == 'true' }}
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
Expand Down Expand Up @@ -69,153 +62,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@v4
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@v4
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

- name: Cache golangci-lint analysis
if: ${{ inputs.language == 'go' }}
uses: actions/cache@v4
with:
path: ~/.cache/golangci-lint
key: golangci-lint-${{ env.CACHE_VERSION }}-${{ steps.versions.outputs.GO_VERSION }}-${{ hashFiles('clients/algoliasearch-client-go/go.sum') }}

# 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 }}
- run: dotnet tool install csharpier --global
if: ${{ inputs.language == 'csharp' }}
shell: bash

# 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@v4
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
32 changes: 20 additions & 12 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ concurrency:
jobs:
setup:
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic-base
defaults:
run:
shell: bash
timeout-minutes: 10
steps:
- name: debugging - dump GitHub context
Expand All @@ -35,10 +40,12 @@ 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
shell: bash
run: |
previousCommit=${{ github.event.before }}
baseRef=${{ github.base_ref }}
Expand All @@ -48,12 +55,10 @@ jobs:

- name: Compute specs matrix
id: spec-matrix
shell: bash
run: yarn workspace scripts createMatrix ${{ steps.diff.outputs.ORIGIN_BRANCH }}

- name: Compute the client codegen matrix
id: gen-matrix
shell: bash
run: yarn workspace scripts createMatrix ${{ steps.diff.outputs.ORIGIN_BRANCH }} clients

- name: check that custom actions are built
Expand Down Expand Up @@ -107,7 +112,7 @@ jobs:
- name: Setup
uses: ./.github/actions/setup
with:
type: minimal
install-node: true

- name: Check script linting
run: yarn scripts:lint
Expand Down Expand Up @@ -136,7 +141,7 @@ jobs:
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: ./.github/actions/setup
with:
type: minimal
install-node: true

- name: Building specs
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
Expand All @@ -152,6 +157,8 @@ jobs:
client_javascript_utils:
timeout-minutes: 10
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic-base
needs: setup
if: ${{ needs.setup.outputs.RUN_GEN_JAVASCRIPT == 'true' }}
strategy:
Expand Down Expand Up @@ -184,8 +191,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 +204,8 @@ jobs:
client_gen_javascript:
timeout-minutes: 10
runs-on: ubuntu-22.04
container:
image: ghcr.io/algolia/apic-base
needs:
- setup
- client_javascript_utils
Expand Down Expand Up @@ -239,7 +247,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 +311,9 @@ 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) }}
needs:
- setup
- specs
Expand Down Expand Up @@ -337,8 +347,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 @@ -409,7 +417,7 @@ jobs:
- name: Setup
uses: ./.github/actions/setup
with:
type: minimal
install-node: true

- name: Push generated code
id: pushGeneratedCode
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup
uses: ./.github/actions/setup
with:
type: minimal
install-node: true

- name: Add notification comment
run: yarn workspace scripts upsertGenerationComment notification
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Setup
uses: ./.github/actions/setup
with:
type: minimal
install-node: true

- name: Add cleanup comment
run: yarn workspace scripts upsertGenerationComment cleanup
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/scheduled-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ jobs:
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
install-node: true

- run: yarn release
env:
Expand Down
2 changes: 1 addition & 1 deletion config/.dart-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.6
3.2.4
Loading
Loading