Code Monkey home page Code Monkey logo

Comments (7)

Wurstnase avatar Wurstnase commented on May 26, 2024 1

I think, the tests itself are a little bit hacky/undocumented stuff using serverless somehow you shouldn't use it, maybe.
When I use the changes and create a demo project using the {git:xyz} it is working without any warning from serverless. So I guess the change itself is correct.

from serverless-plugin-git-variables.

Wurstnase avatar Wurstnase commented on May 26, 2024

With the latest resolver, a plugin should the pattern: https://www.serverless.com/framework/docs/providers/aws/guide/plugins#custom-variable-types

A replacement could look like:

diff --git a/src/index.js b/src/index.js
index a5f1a50..33edef8 100644
--- a/src/index.js
+++ b/src/index.js
@@ -21,15 +21,15 @@ export default class ServerlessGitVariables {
   constructor(serverless, options) {
     this.serverless = serverless
     this.resolvedValues = {}
-    const delegate = serverless.variables.getValueFromSource.bind(serverless.variables)

-    serverless.variables.getValueFromSource = (variableString) => {
-      if (variableString.startsWith(`${GIT_PREFIX}:`)) {
-        const variable = variableString.split(`${GIT_PREFIX}:`)[1]
-        return this._getValue(variable)
+    this.configurationVariablesSources = {
+      [GIT_PREFIX]: {
+        resolve: async ({ address, params, resolveConfigurationProperty, options }) => {
+          return {
+            value: await this._getValue(address)
+          }
+        }
       }
-
-      return delegate(variableString)
     }
     this.hooks = {
       'after:package:initialize': this.exportGitVariables.bind(this),

from serverless-plugin-git-variables.

Wurstnase avatar Wurstnase commented on May 26, 2024

Unfortunately I wasn't able to change the test in lag of serverless documentation and my rough js skills.

from serverless-plugin-git-variables.

henhal avatar henhal commented on May 26, 2024

@Wurstnase I tried to pick up on your work, but something seems strange - I'm not sure the tests simply need to be adapted? Each call now rejects with Invalid variable reference syntax for variable git:describe. You can only reference env vars, options, & files. You can check our docs for more info.. But it should be possible to use custom variables with the resolver syntax you detailed. Did you get the same result or what changes to the tests were you referring to?

from serverless-plugin-git-variables.

Wurstnase avatar Wurstnase commented on May 26, 2024

You may need to update the package.json also. I've updated the complete package.json to the latest packages.
Maybe it will work with less and I don't know how to handle the "peerDependencies" correctly.

However, with this change I was able to use the git plugin within a minimal serverless.yml.

service: test

provider: aws
custom:
  value: ${git:sha1}
plugins:
  - ./lib
diff --git a/package.json b/package.json
index c5832d7..51603f7 100644
--- a/package.json
+++ b/package.json
@@ -42,30 +42,30 @@
   },
   "devDependencies": {
     "@ava/babel": "1.0.1",
-    "@babel/cli": "7.12.1",
-    "@babel/core": "7.12.3",
-    "@babel/preset-env": "7.12.1",
-    "@babel/register": "7.12.1",
-    "ava": "3.13.0",
+    "@babel/cli": "7.13.16",
+    "@babel/core": "7.14.2",
+    "@babel/preset-env": "7.14.2",
+    "@babel/register": "7.13.16",
+    "ava": "3.15.0",
     "babel-plugin-add-module-exports": "1.0.4",
     "coveralls": "3.1.0",
-    "cross-env": "7.0.2",
-    "eslint": "7.12.1",
-    "eslint-config-standard": "16.0.1",
-    "eslint-plugin-ava": "11.0.0",
+    "cross-env": "7.0.3",
+    "eslint": "7.26.0",
+    "eslint-config-standard": "16.0.2",
+    "eslint-plugin-ava": "12.0.0",
     "eslint-plugin-import": "2.22.1",
     "eslint-plugin-node": "11.1.0",
-    "eslint-plugin-promise": "4.2.1",
-    "eslint-plugin-standard": "4.0.2",
-    "fs-extra": "9.0.1",
+    "eslint-plugin-promise": "5.1.0",
+    "eslint-plugin-standard": "4.1.0",
+    "fs-extra": "10.0.0",
     "nyc": "15.1.0",
     "rimraf": "3.0.2",
-    "serverless": "1.17.0",
+    "serverless": ">=2.43.1",
     "tmp": "0.2.1"
   },
   "modules": true,
   "peerDependencies": {
-    "serverless": ">=1.16.0"
+    "serverless": ">=2.43.1"
   },
   "ava": {
     "require": [

from serverless-plugin-git-variables.

henhal avatar henhal commented on May 26, 2024

@Wurstnase Updating package.json didn't help, it's part of #76 and I verified serverless 2.43.1 was used.

from serverless-plugin-git-variables.

jacob-meacham avatar jacob-meacham commented on May 26, 2024

This should now be fixed and work for sls v1, v2, and v3. Thanks!

from serverless-plugin-git-variables.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.