Skip to content

Commit

Permalink
Build: Create major release on CD
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewscwei committed Feb 10, 2024
1 parent 4b2c19e commit 2e8b263
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions .github/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CD
on:
push:
tags: ["v*"]
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create release
uses: actions/github-script@v7
with:
github-token: ${{ secrets.github_token }}
script: |
const tag = process.env.GITHUB_REF.split('/').slice(-1)[0]
const [semVer, prefix, major, minor, patch, prerelease, buildmetadata] = tag.match(/^(v?)(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/) ?? []
try {
await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: tag,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: tag,
})
}
catch (error) {
core.setFailed(error.message)
}
- name: Update major version
run: |
MAJOR_VERSION="$(cut -d '.' -f 1 <<< "$GITHUB_REF_NAME")"
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git tag -fa ${MAJOR_VERSION} -m "Map ${MAJOR_VERSION} to ${GITHUB_REF_NAME}"
git push origin ${MAJOR_VERSION} --force
notify:
needs: [release]
name: Notify
if: always()
runs-on: ubuntu-latest
steps:
- uses: andrewscwei/telegram-action@v1
with:
success: ${{ needs.release.result == 'success' }}
cancelled: ${{ needs.release.result == 'cancelled' }}
bot-token: ${{ secrets.TELEGRAM_DEVOPS_BOT_TOKEN }}
chat-id: ${{ secrets.TELEGRAM_DEVOPS_CHAT_ID }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ansible Roles
# Ansible Roles [![CD](https://github.com/ghoztsys/ansible-roles/workflows/CD/badge.svg)](https://github.com/ghoztsys/ansible-roles/actions/workflows/cd.yml)

Custom Ansible roles.

Expand Down

0 comments on commit 2e8b263

Please sign in to comment.