Skip to content

Commit

Permalink
do not restore file with machine-id
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanderdeijl committed Sep 27, 2023
1 parent 74c8a7c commit ea8c556
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 118 deletions.
106 changes: 53 additions & 53 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,69 @@
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"
name: 'CodeQL'

on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 4 * * 1'
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 4 * * 1'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['javascript']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['javascript']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
index.js
*.tgz
16 changes: 16 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"arrowParens": "avoid",
"overrides": [
{
"files": "*.ts",
"options": {
"parser": "typescript"
}
}
],
"printWidth": 140,
"quoteProps": "consistent",
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A task runner for [Nx](https://nx.dev/) that uses a Google Cloud Storage bucket
npm install --save-dev nx-remotecache-gcs
```

create a Google Cloud Storage bucket. Since this is only a cache, there is no need for a dual- or multi-region bucket, so choose a single [location](https://cloud.google.com/storage/docs/locations) near you.
create a Google Cloud Storage bucket. Since this is only a cache, there is no need for a dual- or multi-region bucket, so choose a single [location](https://cloud.google.com/storage/docs/locations) near you.

```
gsutil mb -p [PROJECT_ID] -l [BUCKET_LOCATION] -b on gs://[BUCKET_NAME]/
Expand Down
20 changes: 15 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ export default function runner(
await mkdirp(cacheDirectory);

// first try to download entire tar file
await pipeline(tarFile.createReadStream(), tar.extract(join(cacheDirectory, hash)));
const ignoreFile = join(cacheDirectory, hash, 'source');
await pipeline(
tarFile.createReadStream(),
tar.extract(join(cacheDirectory, hash), {
// do not extract the `source` file that nx uses to detect that the cache originates from another machine
// see https://github.com/nrwl/nx/pull/18057
ignore: name => name === ignoreFile,
}),
);
// commit file after we're sure all content is downloaded
await commitFile.download({destination:join(cacheDirectory, `${hash}.commit`)});
await commitFile.download({
destination: join(cacheDirectory, `${hash}.commit`),
});
console.log(`retrieved cache from gs://${bucket.name}/${hash}.commit and gs://${bucket.name}/${hash}.tar`);
return true;
} catch (e) {
Expand All @@ -43,8 +53,8 @@ export default function runner(
try {
await Promise.all([
pipeline(tar.pack(join(cacheDirectory, hash)), bucket.file(`${hash}.tar`).createWriteStream()),
bucket.upload(join(cacheDirectory, `${hash}.commit`))
])
bucket.upload(join(cacheDirectory, `${hash}.commit`)),
]);
console.log(`stored cache at gs://${bucket.name}/${hash}.commit and gs://${bucket.name}/${hash}.tar`);
return true;
} catch (e) {
Expand All @@ -54,7 +64,7 @@ export default function runner(
}

function getErrorMessage(e: unknown) {
return typeof e==='object' && !!e && 'message' in e && typeof e.message==='string' ? e.message: ''
return typeof e === 'object' && !!e && 'message' in e && typeof e.message === 'string' ? e.message : '';
}

async function fileExists(f: File) {
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"prepare": "tsc"
"prepare": "prettier -w . && tsc"
},
"repository": {
"type": "git",
Expand All @@ -21,6 +21,7 @@
"@nx/workspace": "^16.9.1",
"@types/node": "^20.7.0",
"@types/yargs": "^17.0.25",
"prettier": "^3.0.3",
"typescript": "^5.2.2"
},
"dependencies": {
Expand Down
Loading

0 comments on commit ea8c556

Please sign in to comment.