R
Railway12mo ago
h246810

Is it possible to get commit hash sent via webhook

I am currently receiving webhook events from my railway deployment, and I was wondering if it is possible to make it so that my railway webhook sends me the commit hash associated with the current build/deployment?
20 Replies
Percy
Percy12mo ago
Project ID: 0423feca-1d4b-493b-a9fa-18ffa127a486
h246810
h24681012mo ago
0423feca-1d4b-493b-a9fa-18ffa127a486
Brody
Brody12mo ago
i thought they already did? that example json in the web ui is just a small fraction of the data actually sent
h246810
h24681012mo ago
this is the full json output that I get

{

type: 'DEPLOY',

project: {

id: '2999b3ba-4058-47fa-95a8-078486652ecc',

name: 'onerous-territory',

description: null,

createdAt: '2023-10-19T23:13:04.387Z'

},

deployment: {

id: '9bce14ba-50fc-4a19-8e48-f9797493bfc3',

meta: {

logsV2: true,

buildOnly: false,

configFile: null,

volumeMounts: [],

rootDirectory: null,

serviceManifest: [Object],

nixpacksProviders: [Array],

fileServiceManifest: {},

ignoreWatchPatterns: true,

propertyFileMapping: {}

},

creator: {

id: 'e68f0116-d498-4ae9-8a55-afc8abdc888e',

name: 'Henry Jacobs',

avatar: 'https://avatars.githubusercontent.com/u/97078529?v=4';

}

},

environment: { id: '34393bb6-c6d0-4281-ad17-be89e49333c8', name: 'production' },

status: 'BUILDING',

timestamp: '2023-11-09T14:02:33.544Z',

service: { id: 'c3a59476-608c-4a8a-807f-ba9c8624170a', name: 'backend' }

}
this is the full json output that I get

{

type: 'DEPLOY',

project: {

id: '2999b3ba-4058-47fa-95a8-078486652ecc',

name: 'onerous-territory',

description: null,

createdAt: '2023-10-19T23:13:04.387Z'

},

deployment: {

id: '9bce14ba-50fc-4a19-8e48-f9797493bfc3',

meta: {

logsV2: true,

buildOnly: false,

configFile: null,

volumeMounts: [],

rootDirectory: null,

serviceManifest: [Object],

nixpacksProviders: [Array],

fileServiceManifest: {},

ignoreWatchPatterns: true,

propertyFileMapping: {}

},

creator: {

id: 'e68f0116-d498-4ae9-8a55-afc8abdc888e',

name: 'Henry Jacobs',

avatar: 'https://avatars.githubusercontent.com/u/97078529?v=4';

}

},

environment: { id: '34393bb6-c6d0-4281-ad17-be89e49333c8', name: 'production' },

status: 'BUILDING',

timestamp: '2023-11-09T14:02:33.544Z',

service: { id: 'c3a59476-608c-4a8a-807f-ba9c8624170a', name: 'backend' }

}
@Brody I don't see a sha commit sha ** @brody I think i just foudn apologies have been absolutely blowing up your line these past few days
Brody
Brody12mo ago
no worries but please enclose code blocks with triple backticks
h246810
h24681012mo ago
you got it Also I am pretty sure I don't get a commit sha when railway up is called from a github workflow.. not sure why investigating
Brody
Brody12mo ago
of course not
h246810
h24681012mo ago
not sure if this makes a difference but the workflow is initiated on PR
Brody
Brody12mo ago
it wasn't deployed from github, it was technically deployed from the filesystem
h246810
h24681012mo ago
fair looking for some work around related to our earlier thread about using a --wait flag on the cli, I am just using webhooks and a proxy to solve the issue for now. Am close the workflow polls the proxy until an update on the deployment can be given
Brody
Brody12mo ago
what would the commit hash be used for in this scenario? couldn't you use the service id?
h246810
h24681012mo ago
logical flow is as follows 1. Deployment gets initiated from workflow, and it begins to poll proxy 2. Right after, webhook is sent from Railway to proxy with the Deployment status and obviously abunch of other stuff that gets sent from railway's webhook 3. The commitHash is taken (or I try to take it) from the railway webhook and I use that as a key in a redis cache that holds the deployment status 4. Every time that the workflow polls for an update, it hits the cache which delivers the most current state held by the commitHash key which is available via a global variable in a github workflow file 5. When an update comes in from Railway saying that the deployment status has changed: SUCCESS, FAILURE... I update the key in the redis cache 6. Next time the poll hits, it will get that updated status If that makes sense so essentially the commitHash is the key piece of information that links both the railway deployment and the workflow and since the workflow runs on PR, you will always be getting the updated value for your specific PR since the commitHash belongs to that PR
Brody
Brody12mo ago
makes sense
h246810
h24681012mo ago
Yeah
Brody
Brody12mo ago
but yeah no hash from something done with railway up
h246810
h24681012mo ago
I just need one unique piece of information that is shared and available via the webhook payload and what's available to me in the workflow yeah Any other ideas of something I can use as a key
Brody
Brody12mo ago
you'd first need to be able to see this key in your github workflow right?
h246810
h24681012mo ago
Yes, I can see the key its available via this global
commit_hash=${{ github.event.pull_request.head.sha }}
commit_hash=${{ github.event.pull_request.head.sha }}
in workflow
Brody
Brody12mo ago
railway up also doesn't provide a way to add variables to a service during deployment I don't currently have any ideas for a key you could use
h246810
h24681012mo ago
no worries Thanks for helping
Want results from more Discord servers?
Add your server