Skip to content

Commit

Permalink
refactor: update actions dependencies (#202)
Browse files Browse the repository at this point in the history
* refactor: update @actions/cache and add availability check

* refactor: update @actions/core to 1.10.0

* refactor: update @actions/exec to 1.1.1

* refactor: update @actions/github to 5.1.1

* refactor: update @actions/io to 1.1.2

* refactor: update @actions/tool-cache to 2.0.1

* test: update cacher tests with new availability checks

* chore: update built files
  • Loading branch information
byCedric authored Jan 4, 2023
1 parent 2606508 commit 259d15d
Show file tree
Hide file tree
Showing 13 changed files with 53,608 additions and 42,658 deletions.
25,268 changes: 14,176 additions & 11,092 deletions build/command/index.js

Large diffs are not rendered by default.

25,268 changes: 14,176 additions & 11,092 deletions build/preview-comment/index.js

Large diffs are not rendered by default.

45,381 changes: 25,035 additions & 20,346 deletions build/setup/index.js

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions build/setup/license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


@azure/core-util
MIT
The MIT License (MIT)

Copyright (c) 2020 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


@azure/logger
MIT
The MIT License (MIT)
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"clean": "rimraf build"
},
"dependencies": {
"@actions/cache": "^1.0.8",
"@actions/core": "^1.9.1",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.0.0",
"@actions/io": "^1.1.1",
"@actions/tool-cache": "^1.7.1"
"@actions/cache": "^3.1.2",
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1",
"@actions/io": "^1.1.2",
"@actions/tool-cache": "^2.0.1"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.1",
Expand Down
4 changes: 1 addition & 3 deletions src/actions/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { createIssueComment, createReaction, issueComment, Reaction } from '../g
import { template } from '../utils';
import { executeAction } from '../worker';

export type CommandInput = ReturnType<typeof commandInput>;

export const MESSAGE_ID = `app:@{projectOwner}/{projectSlug} {cli} {cmdName}`;

export function commandInput() {
Expand All @@ -27,7 +25,7 @@ export function commandInput() {

executeAction(commandAction);

export async function commandAction(input: CommandInput = commandInput()) {
export async function commandAction(input = commandInput()) {
const [comment, context] = issueComment();
if (!comment) {
return;
Expand Down
4 changes: 1 addition & 3 deletions src/actions/preview-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { createIssueComment, pullContext } from '../github';
import { template } from '../utils';
import { executeAction } from '../worker';

export type CommentInput = ReturnType<typeof commentInput>;

export const DEFAULT_ID = `app:@{projectOwner}/{projectSlug} channel:{channel}`;
export const DEFAULT_MESSAGE =
`This pull request was automatically deployed using [Expo GitHub Actions](https://github.com/expo/expo-github-action/tree/main/preview-comment)!\n` +
Expand All @@ -27,7 +25,7 @@ export function commentInput() {

executeAction(commentAction);

export async function commentAction(input: CommentInput = commentInput()) {
export async function commentAction(input = commentInput()) {
const project = await projectInfo(input.project);
if (!project.owner) {
project.owner = await projectOwner();
Expand Down
4 changes: 1 addition & 3 deletions src/actions/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { authenticate } from '../expo';
import { installPackage, resolvePackage } from '../packager';
import { executeAction, findTool, installToolFromPackage, patchWatchers } from '../worker';

export type SetupInput = ReturnType<typeof setupInput>;

export function setupInput() {
return {
easCache: !getInput('eas-cache') || getBooleanInput('eas-cache'),
Expand All @@ -21,7 +19,7 @@ export function setupInput() {

executeAction(setupAction);

export async function setupAction(input: SetupInput = setupInput()) {
export async function setupAction(input = setupInput()) {
if (!input.expoVersion) {
info(`Skipped installing expo-cli: 'expo-version' not provided.`);
} else {
Expand Down
20 changes: 19 additions & 1 deletion src/cacher.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { saveCache, restoreCache, ReserveCacheError } from '@actions/cache';
import { saveCache, restoreCache, ReserveCacheError, isFeatureAvailable } from '@actions/cache';
import { warning } from '@actions/core';
import os from 'os';

import { toolPath } from './worker';

/**
* Determine if the remote cache is available and can be used.
*/
export function cacheIsAvailable(): boolean {
return isFeatureAvailable();
}

/**
* Get the exact cache key for the package.
* We can prefix this when there are breaking changes in this action.
Expand All @@ -18,6 +25,12 @@ export function cacheKey(name: string, version: string, manager: string): string
*/
export async function restoreFromCache(name: string, version: string, manager: string) {
const dir = toolPath(name, version)!;

if (!cacheIsAvailable()) {
warning(`Remote cache is not available, skipping restore from cache...`);
return undefined;
}

try {
if (await restoreCache([dir], cacheKey(name, version, manager))) {
return dir;
Expand All @@ -32,6 +45,11 @@ export async function restoreFromCache(name: string, version: string, manager: s
* This will fetch the tool from the local tool cache.
*/
export async function saveToCache(name: string, version: string, manager: string) {
if (!cacheIsAvailable()) {
warning(`Remote cache is not available, skipping saving to cache...`);
return undefined;
}

try {
await saveCache([toolPath(name, version)], cacheKey(name, version, manager));
} catch (error) {
Expand Down
10 changes: 2 additions & 8 deletions tests/actions/preview-comment.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import * as core from '@actions/core';

import {
CommentInput,
commentInput,
commentAction,
DEFAULT_ID,
DEFAULT_MESSAGE,
} from '../../src/actions/preview-comment';
import { commentInput, commentAction, DEFAULT_ID, DEFAULT_MESSAGE } from '../../src/actions/preview-comment';
import * as expo from '../../src/expo';
import * as github from '../../src/github';
import { mockInput } from '../utils';
Expand Down Expand Up @@ -55,7 +49,7 @@ describe(commentInput, () => {
});

describe(commentAction, () => {
const input: CommentInput = {
const input: ReturnType<typeof commentInput> = {
channel: 'default',
comment: false,
message: DEFAULT_MESSAGE,
Expand Down
4 changes: 2 additions & 2 deletions tests/actions/setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core';

import { SetupInput, setupInput, setupAction } from '../../src/actions/setup';
import { setupInput, setupAction } from '../../src/actions/setup';
import * as cacher from '../../src/cacher';
import * as expo from '../../src/expo';
import * as packager from '../../src/packager';
Expand Down Expand Up @@ -53,7 +53,7 @@ describe(setupInput, () => {
});

describe(setupAction, () => {
const input: SetupInput = {
const input: ReturnType<typeof setupInput> = {
easCache: false,
easVersion: '',
expoCache: false,
Expand Down
7 changes: 7 additions & 0 deletions tests/cacher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,45 @@ describe(cacheKey, () => {

describe(restoreFromCache, () => {
it('skips when cache is unavailable', async () => {
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
jest.mocked(cache.restoreCache).mockRejectedValue(new Error('Cache service url not found'));
await expect(restoreFromCache('expo-cli', '5.0.3', 'yarn')).resolves.toBeUndefined();
});

it('throws when cache has unexpected error', async () => {
jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
jest.mocked(cache.restoreCache).mockRejectedValue(new Error('Node registry is down'));
await expect(restoreFromCache('expo-cli', '5.0.3', 'yarn')).rejects.toThrow('Node registry is down');
});

it('returns expo-cli path from cache when available', async () => {
jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
jest.mocked(cache.restoreCache).mockResolvedValue('fake/path');
await expect(restoreFromCache('expo-cli', '5.0.3', 'yarn')).resolves.toBe(toolPath('expo-cli', '5.0.3'));
});

it('returns nothing when cache is empty', async () => {
jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
jest.mocked(cache.restoreCache).mockResolvedValue(undefined);
await expect(restoreFromCache('eas-cli', '0.46.2', 'npm')).resolves.toBeUndefined();
});
});

describe(saveToCache, () => {
it('skips when cache is unavailable', async () => {
jest.mocked(cache.isFeatureAvailable).mockReturnValue(false);
jest.mocked(cache.saveCache).mockRejectedValue(new Error('Cache service url not found'));
await expect(saveToCache('expo-cli', '5.0.3', 'yarn')).resolves.toBeUndefined();
});

it('throws when cache has unexpected error', async () => {
jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
jest.mocked(cache.saveCache).mockRejectedValue(new Error('Node registry is down'));
await expect(saveToCache('expo-cli', '5.0.3', 'yarn')).rejects.toThrow('Node registry is down');
});

it('saves expo-cli to cache when available', async () => {
jest.mocked(cache.isFeatureAvailable).mockReturnValue(true);
jest.mocked(cache.saveCache).mockResolvedValue(1337);
await expect(saveToCache('expo-cli', '5.0.3', 'yarn')).resolves.toBeUndefined();
});
Expand Down
Loading

0 comments on commit 259d15d

Please sign in to comment.