Skip to content

Commit

Permalink
Merge branch 'release/5.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-meacham committed Nov 21, 2021
2 parents 77b1ae1 + 4f71d6e commit 3c56833
Show file tree
Hide file tree
Showing 9 changed files with 20,940 additions and 2,346 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,26 @@
name: Node.js CI

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: '16.x'
- run: npm ci
- run: npm run build
- run: npm run ci:coverage
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yml
@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ develop ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ develop ]
schedule:
- cron: '21 15 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v2

# 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

# ℹ️ 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

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -72,6 +72,8 @@ For more information on annotated and lightweight tags go to the [git documentat
The tags (`${git:tags}`) is used to get info about which git tags (separated by ::) are pointing to current commit and if none it will show commit ID as fallback.

# Version History
* 5.2.0
- Support for Serverless v2/v3. Switch to github actions
* 5.1.0
- Add messageSubject/messageBody (Thanks @vhenzl)
* 5.0.1
Expand Down
50 changes: 37 additions & 13 deletions lib/index.js
Expand Up @@ -33,28 +33,52 @@ async function _exec(cmd, options = {
class ServerlessGitVariables {
constructor(serverless, options) {
this.serverless = serverless;
this.resolvedValues = {};
const delegate = serverless.variables.getValueFromSource.bind(serverless.variables);
this.resolvedValues = {}; // Back-compat support for Serverless v1

serverless.variables.getValueFromSource = variableString => {
if (variableString.startsWith(`${GIT_PREFIX}:`)) {
const variable = variableString.split(`${GIT_PREFIX}:`)[1];
return this._getValue(variable);
}
if (serverless.variables && serverless.variables.getValueFromSource) {
const delegate = serverless.variables.getValueFromSource.bind(serverless.variables);

return delegate(variableString);
};
serverless.variables.getValueFromSource = variableString => {
if (variableString.startsWith(`${GIT_PREFIX}:`)) {
const variable = variableString.split(`${GIT_PREFIX}:`)[1];
return this._getValue(variable);
}

return delegate(variableString);
};
}

const getValue = this._getValue.bind(this);

this.configurationVariablesSources = {
[GIT_PREFIX]: {
async resolve({
address,
params,
resolveConfigurationProperty,
options
}) {
return {
value: await getValue(address)
};
}

}
}; // Kick this off optimistically on construction, and then also hook it when necessary
// Once resolved once, the call is a very fast

this.exportGitVariables();
this.hooks = {
'after:package:initialize': this.exportGitVariables.bind(this),
'before:offline:start': this.exportGitVariables.bind(this),
'before:offline:start:init': this.exportGitVariables.bind(this)
'before:print:print': async () => this.exportGitVariables(),
'after:package:initialize': async () => this.exportGitVariables(),
'before:offline:start': async () => this.exportGitVariables(),
'before:offline:start:init': async () => this.exportGitVariables()
};
}

async _getValue(variable) {
if (this.resolvedValues[variable]) {
return Promise.resolve(this.resolvedValues[variable]);
return this.resolvedValues[variable];
}

return this._getValueFromGit(variable);
Expand Down

0 comments on commit 3c56833

Please sign in to comment.