Skip to content

Commit

Permalink
feat: Add team for action
Browse files Browse the repository at this point in the history
  • Loading branch information
blue-hope committed Nov 30, 2022
1 parent 30e9c9b commit 3d8c55f
Showing 1 changed file with 50 additions and 34 deletions.
84 changes: 50 additions & 34 deletions .github/workflows/cd-tag-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ on:
env:
required: true
type: string
team:
required: true
type: string

jobs:
deploy-each:
Expand All @@ -21,44 +24,57 @@ jobs:
uses: actions/github-script@v6
with:
script: |
const tagPrefix = "${{ inputs.service }}/${{ inputs.env }}/"
const query = `query($owner:String!, $name:String!) {
repository(owner: $owner, name: $name) {
refs(refPrefix: "refs/tags/${tagPrefix}", last: 1, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
nodes {
name
const checkBranch = () => {
switch ("${{ inputs.team }}") {
case "backend":
return ("${{ inputs.env }}" == "prod" && context.ref == "refs/heads/main") || ("${{ inputs.env }}" == "dev" && context.ref == "refs/heads/develop")
case "frontend":
return context.ref == "refs/heads/main"
}
return false
}
if (checkBranch()) {
const tagPrefix = "${{ inputs.service }}/${{ inputs.env }}/"
const query = `query($owner:String!, $name:String!) {
repository(owner: $owner, name: $name) {
refs(refPrefix: "refs/tags/${tagPrefix}", last: 1, orderBy: {field: ALPHABETICAL, direction: ASC}) {
nodes {
name
}
}
}
}`
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
}
}`
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
}
const lastTagVersion = (await github.graphql(query, variables)).repository.refs.nodes[0]?.name ?? "0.0.0-0"
const newIdx = parseInt(lastTagVersion.split("-")[1]) + 1
const newTagVersion = `${{ env.TODAY }}-${newIdx}`
const tagName = tagPrefix + newTagVersion
const lastTagVersion = (await github.graphql(query, variables)).repository.refs.nodes[0]?.name ?? "0.0.0-0"
const newIdx = lastTagVersion.split("-")[0] === "${{ env.TODAY }}" ? parseInt(lastTagVersion.split("-")[1]) + 1 : 1
const newTagVersion = `${{ env.TODAY }}-${newIdx}`
const tagName = tagPrefix + newTagVersion
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: context.sha
})
let note = "🌱 First deployment with github action 🌱"
try {
note = (await github.rest.repos.generateReleaseNotes({
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: context.sha
})
let note = "🌱 First deployment with github action 🌱"
try {
note = (await github.rest.repos.generateReleaseNotes({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
previous_tag_name: tagPrefix + lastTagVersion
})).data.body
} catch {}
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
previous_tag_name: tagPrefix + lastTagVersion
})).data.body
} catch {}
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: tagName,
body: note
})
name: tagName,
body: note
})
} else {
throw 'Ref match exception'
}

0 comments on commit 3d8c55f

Please sign in to comment.