Skip to content

Commit

Permalink
ci: npmrc update & add ec2-types sync schedule (#24)
Browse files Browse the repository at this point in the history
* ci: add default npmrc and remove npmrc generation

* chore: rename util to scripts

* ci: add ec2-types sync schedule

* ci: revert changes related with npmrc

* ci: remove git status checks & add aws secrets

* ci(scripts): exit(1) on credential failure

* ci: reorder steps and update snapshot

* ci: update exclude patterns
  • Loading branch information
hoonoh authored Oct 31, 2019
1 parent 7ca556b commit bf340d2
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- bash: |
echo "##vso[task.setvariable variable=PACKAGE_VERSION]$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d '[[:space:]]')"
echo "##vso[task.setvariable variable=CURRENT_GIT_TAG]$(git describe --tags | tr -d '[:space:]')"
echo "//registry.npmjs.org/:_authToken=$(NPM_TOKEN)" >> .npmrc
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}\n" >> .npmrc
- script: npm dist-tag add aws-spot-price@$(PACKAGE_VERSION) $(CURRENT_GIT_TAG)
displayName: "NPM dist-tag $(CURRENT_GIT_TAG)"
env:
Expand Down
2 changes: 1 addition & 1 deletion .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ exclude_patterns:
- "package.json"
- "patches/"
- "README.md"
- "scripts/"
- "src/**/*.spec.ts"
- "test/"
- "tsconfig.json"
- "util/"
- "yarn.lock"
- sonar-project.properties
- sonar-project.properties
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/ec2-gen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: keep ec2 types up to date

on:
schedule:
- cron: "0 0 * * *"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Install dependencies
run: yarn --frozen-lockfile

- name: Generate ec2-types
run: yarn build:ec2-types
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Build
run: yarn build

- name: Check linting
run: yarn lint

- name: Check types
run: yarn lint:types

- name: Run tests and update snapshots
run: yarn test -u

- name: Log git diffs
run: git diff

- name: Create Pull Request
uses: peter-evans/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MESSAGE: "fix: update ec2-types"
PULL_REQUEST_TITLE: "fix: update ec2-types"
PULL_REQUEST_BRANCH: ec2-types/patch
BRANCH_SUFFIX: none
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"scripts": {
"prepublishOnly": "yarn clean && yarn build",
"clean": "rm -rf dist && rm -rf coverage",
"build:ec2-types": "ts-node -T util/generate-ec2-types.ts",
"build:ec2-types": "ts-node -T scripts/generate-ec2-types.ts",
"build": "patch-package && webpack",
"changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
"test": "patch-package && jest --runInBand --verbose",
Expand Down
9 changes: 8 additions & 1 deletion util/generate-ec2-types.ts → scripts/generate-ec2-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ const sortInstances = (i1: string, i2: string): number => {
};

const getEc2Types = async (): Promise<string> => {
const allInstances = (await getGlobalSpotPrices({ silent: true })).reduce(
let prices;
try {
prices = await getGlobalSpotPrices({ silent: true });
} catch (error) {
console.log(`getGlobalSpotPrices error: ${error}`);
process.exit(1);
}
const allInstances = prices.reduce(
(list, cur) => {
if (cur.InstanceType && !list.includes(cur.InstanceType)) list.push(cur.InstanceType);
return list;
Expand Down
File renamed without changes.
26 changes: 18 additions & 8 deletions src/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Ec2SpotPriceError extends Error {
Object.setPrototypeOf(this, Ec2SpotPriceError.prototype);
}

readonly region: string;
readonly region: Region;

readonly code: string;
}
Expand Down Expand Up @@ -87,7 +87,13 @@ const getEc2SpotPrice = async (options: {
rtn = list.filter(history => history.InstanceType).sort(sortSpotPrice);
}
} catch (error) {
if (error && error.code && (error.code === 'AuthFailure' || error.code === 'OptInRequired')) {
if (
error &&
error.code &&
(error.code === 'AuthFailure' ||
error.code === 'OptInRequired' ||
error.code === 'CredentialsError')
) {
throw new Ec2SpotPriceError(error.message, region, error.code);
} else {
console.error(
Expand Down Expand Up @@ -173,12 +179,16 @@ export const getGlobalSpotPrices = async (options?: {
return regionsPrices;
} catch (error) {
/* istanbul ignore if */
if (error instanceof Ec2SpotPriceError && spinner) {
spinner.fail(`Failed to retrieve data from ${error.region}. (${error.code})`);
spinner = ora({
text: spinnerText || spinner.text,
discardStdin: false,
}).start();
if (error instanceof Ec2SpotPriceError) {
if (spinner) {
spinner.fail(`Failed to retrieve data from ${error.region}. (${error.code})`);
spinner = ora({
text: spinnerText || spinner.text,
discardStdin: false,
}).start();
} else {
throw error;
}
} else {
console.error(error);
}
Expand Down

0 comments on commit bf340d2

Please sign in to comment.