Skip to content

Commit

Permalink
CI: Update release flow
Browse files Browse the repository at this point in the history
  • Loading branch information
btnguyen2k committed Feb 21, 2024
1 parent dccaf20 commit 590be05
Showing 1 changed file with 94 additions and 89 deletions.
183 changes: 94 additions & 89 deletions .github/workflows/gjrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,97 +58,102 @@ jobs:
tag-only: true
path: 'gjrc/'

Dummy:
Release:
runs-on: ubuntu-latest
if: |
github.event.pull_request.merged == true &&
github.ref == 'refs/heads/gjrc'
needs: [ 'ReleaseDryRun' ]
permissions:
contents: write
outputs:
RESULT: ${{ needs.ReleaseDryRun.outputs.RESULT }}
VERSION: ${{ needs.ReleaseDryRun.outputs.VERSION }}
RELEASE_NOTES: ${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}
steps:
- uses: actions/checkout@v4
- name: Update module meta
run: |
RESULT='${{ needs.ReleaseDryRun.outputs.RESULT }}'
VERSION='${{ needs.ReleaseDryRun.outputs.VERSION }}'
RELEASE_NOTES='${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}'
MODULE=gjrc
echo "πŸ•˜ Updating module meta..."
echo " - RESULT: ${RESULT}"
echo " - VERSION: ${VERSION}"
echo " - RELEASE_NOTES: ${RELEASE_NOTES}"
if [ "${RESULT}" == "SUCCESS" ]; then
DATE=`date +%Y-%m-%d`
FILE_CHANGELOG="${MODULE}/CHANGELOG.md"
FILE_MODULE="${MODULE}/module.go"
head -1 ${FILE_CHANGELOG} > .temp.md
echo -e "\n## ${DATE} - v${VERSION}\n\n${RELEASE_NOTES}" >> .temp.md
tail -n +2 ${FILE_CHANGELOG} >> .temp.md
mv -f .temp.md ${FILE_CHANGELOG}
echo ========== content of ${FILE_CHANGELOG} ==========
cat ${FILE_CHANGELOG}
sed -i -E "s/^(\s*Version\s*=\s*)\"[^\"]+\"/\1\"${VERSION}\"/" ${FILE_MODULE}
echo ========== content of ${FILE_MODULE} ==========
cat ${FILE_MODULE}
echo ========== update .go and .md files ==========
sed -i -E "s/<<VERSION>>/v${VERSION}/" ${MODULE}/*.go
sed -i -E "s/<<VERSION>>/v${VERSION}/" ${MODULE}/*.md
echo ========== commit updates ==========
git config --global user.email "<>"
git config --global user.name "CI Build"
git commit -am "Update ${FILE_CHANGELOG} and ${FILE_MODULE} for new version ${VERSION}"
git push origin ${MODULE} -f
echo ========== tag ==========
git tag -f -a "${MODULE}/v${VERSION}" -m "Release ${MODULE}/v${VERSION}"
git push origin "${MODULE}/v${VERSION}" -f
echo "βœ… Done."
else
echo "❎ SKIPPED."
fi
- name: Cleanup file .semrelease/this_release
run: |
RESULT='${{ needs.ReleaseDryRun.outputs.RESULT }}'
if [ "${RESULT}" == "SUCCESS" ]; then
VERSION='${{ needs.ReleaseDryRun.outputs.VERSION }}'
echo "πŸ•˜ Cleaning up file .semrelease/this_release..."
echo "Cleanup post releasing version ${VERSION}" > .semrelease/this_release
git config --global user.email "<>"
git config --global user.name "CI Build"
git commit -am "Cleanup file .semrelease/this_release post releasing version ${VERSION}"
git push -f
echo "βœ… Done."
else
echo "❎ SKIPPED."
fi
MergeToMaster:
runs-on: ubuntu-latest
needs: [ 'Release' ]
permissions:
pull-requests: write
steps:
- run: |
set
- uses: actions/github-script@v7
env:
RESULT: ${{ needs.Release.outputs.RESULT }}
RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
with:
script: |
console.log(context)
# Release:
# runs-on: ubuntu-latest
# if: |
# github.event.pull_request.merged == true &&
# github.ref_name == 'gjrc'
# needs: [ 'ReleaseDryRun' ]
# permissions:
# contents: write
# outputs:
# RESULT: ${{ needs.ReleaseDryRun.outputs.RESULT }}
# VERSION: ${{ needs.ReleaseDryRun.outputs.VERSION }}
# RELEASE_NOTES: ${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}
# steps:
# - uses: actions/checkout@v4
# - name: Update module meta
# run: |
# RESULT='${{ needs.ReleaseDryRun.outputs.RESULT }}'
# VERSION='${{ needs.ReleaseDryRun.outputs.VERSION }}'
# RELEASE_NOTES='${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}'
# MODULE=gjrc
# echo "πŸ•˜ Updating module meta..."
# echo " - RESULT: ${RESULT}"
# echo " - VERSION: ${VERSION}"
# echo " - RELEASE_NOTES: ${RELEASE_NOTES}"
# if [ "${RESULT}" == "SUCCESS" ]; then
# DATE=`date +%Y-%m-%d`
# FILE_CHANGELOG="${MODULE}/CHANGELOG.md"
# FILE_MODULE="${MODULE}/module.go"
# head -1 ${FILE_CHANGELOG} > .temp.md
# echo -e "\n## ${DATE} - v${VERSION}\n\n${RELEASE_NOTES}" >> .temp.md
# tail -n +2 ${FILE_CHANGELOG} >> .temp.md
# mv -f .temp.md ${FILE_CHANGELOG}
# echo ========== content of ${FILE_CHANGELOG} ==========
# cat ${FILE_CHANGELOG}
#
# sed -i -E "s/^(\s*Version\s*=\s*)\"[^\"]+\"/\1\"${VERSION}\"/" ${FILE_MODULE}
# echo ========== content of ${FILE_MODULE} ==========
# cat ${FILE_MODULE}
#
# echo ========== update .go and .md files ==========
# sed -i -E "s/<<VERSION>>/v${VERSION}/" ${MODULE}/*.go
# sed -i -E "s/<<VERSION>>/v${VERSION}/" ${MODULE}/*.md
#
# echo ========== commit updates ==========
# git config --global user.email "<>"
# git config --global user.name "CI Build"
# git commit -am "Update ${FILE_CHANGELOG} and ${FILE_MODULE} for new version ${VERSION}"
# git push origin ${MODULE} -f
#
# echo ========== tag ==========
# git tag -f -a "${MODULE}/v${VERSION}" -m "Release ${MODULE}/v${VERSION}"
# git push origin "${MODULE}/v${VERSION}" -f
#
# echo "βœ… Done."
# else
# echo "❎ SKIPPED."
# fi
#
# MergeToMaster:
# runs-on: ubuntu-latest
# needs: [ 'Release' ]
# permissions:
# pull-requests: write
# steps:
# - uses: actions/github-script@v7
# env:
# RESULT: ${{ needs.Release.outputs.RESULT }}
# RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
# with:
# script: |
# if (process.env['RESULT'] != 'SUCCESS') {
# console.log('❎ SKIPPED.');
# return;
# }
# const {data: pr} = await github.rest.pulls.create({
# owner: context.repo.owner,
# repo: context.repo.repo,
# title: "Merge branch gjrc to master after releasing new version ${{ needs.Release.outputs.VERSION }}",
# body: process['env']['RELEASE_NOTES'],
# head: 'gjrc',
# base: 'master',
# maintainer_can_modify: true,
# });
# console.log('βœ… Created PR: ', pr);
if (process.env['RESULT'] != 'SUCCESS') {
console.log('❎ SKIPPED.');
return;
}
const {data: pr} = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "Merge branch gjrc to master after releasing new version ${{ needs.Release.outputs.VERSION }}",
body: process['env']['RELEASE_NOTES'],
head: 'gjrc',
base: 'master',
maintainer_can_modify: true,
});
console.log('βœ… Created PR: ', pr);

0 comments on commit 590be05

Please sign in to comment.