Skip to content

chore(ci): make the artifacts dynamic #689

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

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
91 changes: 25 additions & 66 deletions .github/actions/restore-artifacts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,40 @@ inputs:
type:
description: Type of artifacts to restore (`all` | `specs` | `js_utils`)
required: false
php:
description: Whether this job ran or not
matrix:
description: The matrix of language clients to download
required: false
java:
description: Whether this job ran or not
required: false
javascript:
description: Whether this job ran or not
token:
description: GITHUB_TOKEN from secrets (not accessible from here)
required: false

runs:
using: composite
steps:
# Bundled specs
- name: specs
if: ${{ inputs.type == 'all' || inputs.type == 'specs' }}
uses: actions/download-artifact@v3
with:
name: specs
path: specs/bundled/

# JavaScript utils
- name: client-javascript-utils-client-common
if: ${{ (inputs.javascript == 'true' && inputs.type == 'all') || inputs.type == 'js_utils' }}
uses: actions/download-artifact@v3
with:
name: client-javascript-utils-client-common
path: clients/algoliasearch-client-javascript/packages/client-common/

- name: client-javascript-utils-requester-browser-xhr
if: ${{ (inputs.javascript == 'true' && inputs.type == 'all') || inputs.type == 'js_utils' }}
uses: actions/download-artifact@v3
with:
name: client-javascript-utils-requester-browser-xhr
path: clients/algoliasearch-client-javascript/packages/requester-browser-xhr/

- name: client-javascript-utils-requester-node-http
if: ${{ (inputs.javascript == 'true' && inputs.type == 'all') || inputs.type == 'js_utils' }}
uses: actions/download-artifact@v3
with:
name: client-javascript-utils-requester-node-http
path: clients/algoliasearch-client-javascript/packages/requester-node-http/

# JavaScript
- name: Download clients-javascript artifact
if: ${{ inputs.javascript == 'true' && inputs.type == 'all' }}
uses: actions/download-artifact@v3
with:
name: clients-javascript

- name: Unzip clients-javascript artifact
if: ${{ inputs.javascript == 'true' && inputs.type == 'all' }}
shell: bash
run: unzip -q -o clients-javascript.zip && rm clients-javascript.zip

# PHP
- name: Download clients-php artifact
if: ${{ inputs.php == 'true' && inputs.type == 'all' }}
uses: actions/download-artifact@v3
with:
name: clients-php

- name: Unzip clients-php artifact
if: ${{ inputs.php == 'true' && inputs.type == 'all' }}
shell: bash
run: unzip -q -o clients-php.zip && rm clients-php.zip

# Java
- name: Download clients-java artifact
if: ${{ inputs.java == 'true' && inputs.type == 'all' }}
if: ${{ inputs.type == 'all' }}
uses: actions/download-artifact@v3
with:
name: clients-java

- name: Unzip clients-java artifact
if: ${{ inputs.java == 'true' && inputs.type == 'all' }}
# Clients and tests
- name: Download clients and tests artifacts
if: ${{ inputs.type == 'all' }}
shell: bash
run: unzip -q -o clients-java.zip && rm clients-java.zip
env:
GITHUB_TOKEN: ${{ inputs.token }}
run: |
echo ${{ inputs.matrix }} | jq -c '.client []' | while read client; do
language=$(jq -r '.language' <<< $client)
artifact="clients-$language"
echo "Downloading $artifact artifacts"

rm -rf $(jq -r '.path' <<< $client)
rm -rf $(jq -r '.testToDelete' <<< $client) || true

# Get the artifact id
id=$(gh api -H "Accept: application/vnd.github.v3+json" /repos/algolia/api-clients-automation/actions/runs/${{ github.run_id }}/artifacts -q ".artifacts [] | select(.name==\"$artifact\") | .id")
echo "Artifact id: $id"
gh api -H "Accept: application/vnd.github.v3+json" /repos/algolia/api-clients-automation/actions/artifacts/$id/zip > $artifact.zip
unzip -q -o $artifact.zip && rm $artifact.zip
done
133 changes: 7 additions & 126 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ concurrency:
cancel-in-progress: true

# Uncomment the line below to enable artifacts debugging
# env:
# ACTIONS_RUNNER_DEBUG: true
env:
ACTIONS_RUNNER_DEBUG: true

jobs:
setup:
Expand All @@ -35,25 +35,6 @@ jobs:
with:
type: matrix

- name: Lint GitHub actions
run: yarn github-actions:lint

- name: Lint generators
run: |
yarn cli format java generators
diff=$(git status --porcelain ./generators | wc -l)

if [[ $diff > 0 ]]; then
echo "Format the generators folder by running 'yarn docker format java generators'"
fi

exit $diff

- name: Lint json files
run: |
yarn eslint --ext=json .
echo 'Use yarn fix:json to fix issues'

outputs:
RUN_SCRIPTS: ${{ steps.setup.outputs.RUN_SCRIPTS }}

Expand Down Expand Up @@ -101,30 +82,6 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Cache bundled specs
id: cache
uses: actions/cache@v3
with:
key: ${{ matrix.client.cacheKey }}
path: ${{ matrix.client.bundledPath }}

- 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' }}
run: yarn cli build specs ${{ matrix.client.toRun }}

- name: Store bundled specs
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: specs
path: ${{ matrix.client.bundledPath }}

client_javascript_utils:
timeout-minutes: 10
runs-on: ubuntu-20.04
Expand All @@ -139,38 +96,6 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Cache '${{ matrix.client }}' client folder
id: cache
uses: actions/cache@v3
with:
key: |
${{ matrix.client }}-${{ hashFiles(
format('clients/algoliasearch-client-javascript/packages/{0}/**', matrix.client),
'yarn.lock'
)}}
path: clients/algoliasearch-client-javascript/packages/${{ matrix.client }}

- name: Setup
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: ./.github/actions/setup
with:
type: minimal

- name: Build '${{ matrix.client }}' client
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: yarn workspace algoliasearch-client-javascript build ${{ matrix.client }}

- name: Run tests for 'client-common'
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client == 'client-common' }}
run: yarn workspace @experimental-api-clients-automation/client-common test

- name: Store '${{ matrix.client }}' JavaScript utils package
uses: actions/upload-artifact@v3
with:
if-no-files-found: error
name: client-javascript-utils-${{ matrix.client }}
path: clients/algoliasearch-client-javascript/packages/${{ matrix.client }}

client_gen:
timeout-minutes: 15
runs-on: ubuntu-20.04
Expand All @@ -196,53 +121,10 @@ jobs:
key: ${{ matrix.client.cacheKey }}
path: ${{ matrix.client.path }}

- name: Download specs artifacts
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: ./.github/actions/restore-artifacts
with:
type: specs

# Always download the utils for js, in case they changed we want to include them in the zip
- name: Download JavaScript utils artifacts
if: ${{ matrix.client.language == 'javascript' }}
uses: ./.github/actions/restore-artifacts
with:
type: js_utils

- name: Setup
uses: ./.github/actions/setup

- name: Generate clients
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: yarn cli generate ${{ matrix.client.language }} ${{ matrix.client.toRun }}

- name: Build clients
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language != 'php' }}
run: yarn cli build clients ${{ matrix.client.language }} ${{ matrix.client.toRun }}

- name: Build JavaScript 'algoliasearch' client
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }}
run: yarn cli build clients javascript algoliasearch

- name: Run JavaScript 'algoliasearch' client tests
if: ${{ steps.cache.outputs.cache-hit != 'true' && matrix.client.language == 'javascript' }}
run: yarn workspace @experimental-api-clients-automation/algoliasearch test

- name: Clean CTS output before generate
run: rm -rf ${{ matrix.client.testsToDelete }} || true

- name: Generate CTS
run: yarn cli cts generate ${{ matrix.client.language }} ${{ matrix.client.toRun }}

- name: Update `yarn.lock` for JavaScript release
if: ${{ matrix.client.language == 'javascript' && (startsWith(github.head_ref, 'chore/prepare-release-') || github.ref == 'refs/heads/main') }}
run: YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install

- name: Run CTS
run: yarn cli cts run ${{ matrix.client.language }}

- name: Zip artifact before storing
run: zip -r -y clients-${{ matrix.client.language }}.zip ${{ matrix.client.path }} ${{ matrix.client.testsToStore }} -x "**/node_modules**" "clients/algoliasearch-client-javascript/.yarn**" "**/.github**"
run:
zip -r -y clients-${{ matrix.client.language }}.zip ${{ matrix.client.path }} ${{ matrix.client.testsToStore }} -x \
"**/node_modules**" "clients/algoliasearch-client-javascript/.yarn**" "**/.github**" "**/build/**" "**/dist/**" "**/.gradle/**" "**/bin/**" "**/vendor/**"

- name: Store ${{ matrix.client.language }} clients
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -273,9 +155,8 @@ jobs:
uses: ./.github/actions/restore-artifacts
with:
type: all
javascript: ${{ needs.setup.outputs.RUN_GEN_JAVASCRIPT }}
php: ${{ needs.setup.outputs.RUN_GEN_PHP }}
java: ${{ needs.setup.outputs.RUN_GEN_JAVA }}
matrix: ${{ toJSON(needs.setup.outputs.GEN_MATRIX) }}
token: ${{ secrets.ALGOLIA_BOT_TOKEN }}

- name: Setup
uses: ./.github/actions/setup
Expand Down
4 changes: 1 addition & 3 deletions scripts/ci/husky/pre-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ async function preCommit() {
}
}

const stagedFiles = (
await run('git diff --name-only --cached --diff-filter=d')
).split('\n');
const stagedFiles = (await run('git diff --name-only --cached')).split('\n');

const toUnstage = micromatch.match(stagedFiles, getPatterns());

Expand Down