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(scripts): catch up on deprecated github actions #1345

Merged
merged 5 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 5 additions & 8 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ inputs:
type:
description: Type of setup, `minimal` will only setup the JavaScript monorepo, `matrix` will set the run variables.
required: false
workflow_name:
description: Name of the workflow that is executing this action.
required: false
language:
description: the language for which to install deps
required: false
Expand All @@ -24,7 +21,7 @@ runs:
# Java for code generation
- name: Install Java
if: inputs.type != 'minimal'
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11.0.4
Expand All @@ -41,15 +38,15 @@ runs:

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

- name: Get yarn cache directory path
shell: bash
id: yarn-cache-dir
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- name: Restore Yarn
uses: actions/cache@v3
Expand All @@ -73,7 +70,7 @@ runs:
if: ${{ inputs.language == 'javascript' }}
shell: bash
id: yarn-cache-dir-client
run: echo "::set-output name=dir::$(cd clients/algoliasearch-client-javascript && yarn config get cacheFolder)"
run: echo "dir=$(cd clients/algoliasearch-client-javascript && yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- name: Restore Yarn js-client
if: ${{ inputs.language == 'javascript' }}
Expand Down Expand Up @@ -134,7 +131,7 @@ runs:
run: |
if ${{ steps.gen-matrix.outputs.RUN_GEN_JAVASCRIPT || steps.diff.outputs.JAVASCRIPT_UTILS_CHANGED > 0 }}; then
echo "Running JavaScript utils: true"
echo "::set-output name=RUN_JS_UTILS::true"
echo "RUN_JS_UTILS=true" >> $GITHUB_OUTPUT
fi

outputs:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"

- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
needs: setup
if: ${{ needs.setup.outputs.RUN_SCRIPTS == 'true' }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup
uses: ./.github/actions/setup
Expand All @@ -97,7 +97,7 @@ jobs:
timeout-minutes: 10
needs: setup
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Cache bundled specs
id: cache
Expand Down Expand Up @@ -136,7 +136,7 @@ jobs:
- requester-node-http
- requester-fetch
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Cache '${{ matrix.client }}' client folder
id: cache
Expand Down Expand Up @@ -184,7 +184,7 @@ jobs:
strategy:
matrix: ${{ fromJSON(needs.setup.outputs.GEN_MATRIX) }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Cache clients folder
id: cache
Expand Down Expand Up @@ -247,7 +247,7 @@ jobs:
if: ${{ matrix.client.language == 'javascript' }}
shell: bash
id: yarn-cache-dir-tests
run: echo "::set-output name=dir::$(cd ${{ matrix.client.testsRootFolder }} && yarn config get cacheFolder)"
run: echo "dir=$(cd ${{ matrix.client.testsRootFolder }} && yarn config get cacheFolder)" >> $GITHUB_OUTPUT

- name: Restore Yarn js tests
if: ${{ matrix.client.language == 'javascript' }}
Expand Down Expand Up @@ -288,7 +288,7 @@ jobs:
!contains(needs.*.result, 'cancelled') &&
!contains(needs.*.result, 'failure')
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
timeout-minutes: 10
if: (github.event.action == 'opened' || github.event.action == 'synchronize') && github.event.number
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
Expand All @@ -32,7 +32,7 @@ jobs:
timeout-minutes: 10
if: github.event.action == 'closed'
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
runs-on: ubuntu-20.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Pull Request title rules
uses: deepakputhraya/action-pr-title@v1.0.2
uses: Slashgear/action-check-pr-title@v4.3.0
with:
regex: '^(docs|chore)|((?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\((?:clients|generators|javascript|php|java|cts|specs|scripts|ci|templates|deps)\)): .+'
regexp: '^(docs|chore)|((?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\((?:clients|generators|javascript|php|java|cts|specs|scripts|ci|templates|deps)\)): .+'
2 changes: 1 addition & 1 deletion .github/workflows/scheduled-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Scheduled Release
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_PRIVATE_KEY_ID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PRIVATE_KEY_PASSWORD }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install Java
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11.0.4
Expand All @@ -36,7 +36,7 @@ jobs:
id: snapshot
run: |
if [[ $(cat ./gradle.properties | grep 'VERSION_NAME=.*-SNAPSHOT') ]]; then
echo "::set-output name=IS_SNAPSHOT::true"
echo "IS_SNAPSHOT=true" >> $GITHUB_OUTPUT
fi

- name: Release Artifacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-20.04
if: "startsWith(github.event.head_commit.message, 'chore: release')"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install Node
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version-file: .nvmrc
cache: yarn
Expand Down
15 changes: 7 additions & 8 deletions scripts/ci/githubActions/createMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {
SpecMatrix,
ToRunMatrix,
} from './types';
import { computeCacheKey, isBaseChanged } from './utils';
import { computeCacheKey, isBaseChanged, setOutput } from './utils';

// This empty matrix is required by the CI, otherwise it throws
const EMPTY_MATRIX = { client: ['no-run'] };
Expand Down Expand Up @@ -150,16 +150,15 @@ async function getClientMatrix(baseBranch: string): Promise<void> {
testsToDelete,
testsToStore,
});
console.log(`::set-output name=RUN_GEN_${language.toUpperCase()}::true`);
console.log(`name=RUN_GEN_${language.toUpperCase()}::true`);
}

const shouldRun = clientMatrix.client.length > 0;

console.log(`::set-output name=RUN_GEN::${shouldRun}`);
console.log(
`::set-output name=GEN_MATRIX::${JSON.stringify(
shouldRun ? clientMatrix : EMPTY_MATRIX
)}`
await setOutput('RUN_GEN', shouldRun);
await setOutput(
'GEN_MATRIX',
JSON.stringify(shouldRun ? clientMatrix : EMPTY_MATRIX)
);
}

Expand Down Expand Up @@ -187,7 +186,7 @@ async function getSpecMatrix(): Promise<void> {
]),
};

console.log(`::set-output name=MATRIX::${JSON.stringify(ciMatrix)}`);
await setOutput('MATRIX', JSON.stringify(ciMatrix));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/githubActions/setRunVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { CLIENTS_JS_UTILS } from '../../common';
import { getLanguageFolder } from '../../config';

import { isBaseChanged } from './utils';
import { isBaseChanged, setOutput } from './utils';

const JS_CLIENT_FOLDER = getLanguageFolder('javascript');
const JAVA_CLIENT_FOLDER = getLanguageFolder('java');
Expand Down Expand Up @@ -81,7 +81,7 @@ async function setRunVariables({
}): Promise<void> {
console.log(`Checking diff between ${originBranch} and HEAD`);

console.log(`::set-output name=ORIGIN_BRANCH::${originBranch}`);
await setOutput('ORIGIN_BRANCH', originBranch);

await isBaseChanged(originBranch, DEPENDENCIES, true);
}
Expand Down
16 changes: 11 additions & 5 deletions scripts/ci/githubActions/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* eslint-disable no-console */
import crypto from 'crypto';
import fsp from 'fs/promises';
import { EOL } from 'os';

import { hashElement } from 'folder-hash';

import { toAbsolutePath } from '../../common';
import { getNbGitDiff } from '../utils';

/**
* This cache key holds the hash of the common dependencies of all the clients.
*/
Expand Down Expand Up @@ -63,26 +64,31 @@ export async function computeCacheKey(
/**
* Determines if changes have been found in the `dependencies`, compared to the `baseBranch`.
*
* If `setOutput` is true, it will set log the variable values for the CI.
* If `output` is true, it will set log the variable values for the CI.
*/
export async function isBaseChanged(
baseBranch: string,
dependencies: Record<string, string[]>,
setOutput?: boolean
output?: boolean
): Promise<boolean> {
for (const [key, path] of Object.entries(dependencies)) {
const diff = await getNbGitDiff({
branch: baseBranch,
path: path.join(' '),
});

if (setOutput) {
if (output) {
console.log(`Found ${diff} changes for '${key}'`);
console.log(`::set-output name=${key}::${diff}`);
await setOutput(key, diff);
} else if (diff > 0) {
return true;
}
}

return false;
}

export async function setOutput(key: string, value: any): Promise<void> {
const output = process.env.GITHUB_OUTPUT!;
await fsp.writeFile(output, `${key}=${value}${EOL}`);
}