Skip to content

Commit

Permalink
fix: empty commit for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipe Forattini committed Jul 18, 2022
1 parent 2452364 commit f075b96
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/actions/config-scrapper/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/actions/config-scrapper/index.js.map

Large diffs are not rendered by default.

44 changes: 32 additions & 12 deletions src/actions/config-scrapper/src/deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ const core = require("@actions/core");
const github = require("@actions/github");

module.exports = async (analysis) => {
let environment = core.getInput('environment', { required: false });
let containerRegistry = core.getInput('containerRegistry', { required: true });

const commitSha = github.context.sha.substring(0,7)
const [ organization, name ] = github.context.payload.repository.full_name.split('/')
const imageFullName = [ containerRegistry, organization, name].join('/')

Expand All @@ -12,37 +14,55 @@ module.exports = async (analysis) => {
analysis.outputs.environment = analysis.environment
}


let tag = `c-${commitSha}`
let tags = [
`latest`,
`r-${github.context.runNumber}`,
`c-${github.context.sha.substring(0,7)}`,
`c-${commitSha}`,
`b-${github.context.ref.replace('refs/heads/', '').replace('/', '-')}`,
`u-${github.context.actor}`,
]

// push
if (github.context.payload.head_commit) {
const committedAt = new Date(github.context.payload.head_commit.timestamp)

if (environment) {
tag = `e-${environment}-c-${commitSha}`
tags = tags.concat([
`d-${committedAt.toISOString().substring(0,10)}`,
`t-${committedAt.getTime()}`,
`e-${environment}-latest`,
`e-${environment}-r-${github.context.runNumber}`,
`e-${environment}-c-${commitSha}`,
`e-${environment}-b-${github.context.ref.replace('refs/heads/', '').replace('/', '-')}`,
`e-${environment}-u-${github.context.actor}`,
])
}

// pull_request
if (github.context.payload.pull_request) {
const committedAt = new Date(github.context.payload.pull_request.updatedAt)

// push
const committedAt = github.context.payload.head_commit
? new Date(github.context.payload.head_commit.timestamp) // push
: github.context.payload.pull_request
? new Date(github.context.payload.pull_request.updatedAt) // pr
: null

if (committedAt) {
tags = tags.concat([
`d-${committedAt.toISOString().substring(0,10)}`,
`t-${committedAt.getTime()}`,
])

if (environment) {
tags = tags.concat([
`e-${environment}-d-${committedAt.toISOString().substring(0,10)}`,
`e-${environment}-t-${committedAt.getTime()}`,
])
}
}

tags = tags.map(t => `${imageFullName}:${t}`)

analysis.deployment.tag = tag
analysis.deployment.tags = tags
analysis.deployment.tagsString = tags.join(',')

// outputs
analysis.outputs.event = analysis.event
analysis.outputs.tag = analysis.deployment.tag
analysis.outputs.tags = analysis.deployment.tagsString
}

0 comments on commit f075b96

Please sign in to comment.