Skip to content

Commit

Permalink
refactor: update @actions/cache and add availability check
Browse files Browse the repository at this point in the history
  • Loading branch information
byCedric committed Jan 4, 2023
1 parent 2606508 commit ef24e69
Show file tree
Hide file tree
Showing 12 changed files with 34,787 additions and 32,258 deletions.
13,856 changes: 7,233 additions & 6,623 deletions build/command/index.js

Large diffs are not rendered by default.

13,856 changes: 7,233 additions & 6,623 deletions build/preview-comment/index.js

Large diffs are not rendered by default.

39,114 changes: 20,184 additions & 18,930 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clean": "rimraf build"
},
"dependencies": {
"@actions/cache": "^1.0.8",
"@actions/cache": "^3.1.2",
"@actions/core": "^1.9.1",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.0.0",
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
19 changes: 18 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,10 @@ 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()) {
return warning(`Remote cache is not available, skipping saving to cache...`);
}

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

0 comments on commit ef24e69

Please sign in to comment.