Merge pull request #83 from btnguyen2k/reddo #53
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: reddo | |
on: | |
push: | |
branches: [ 'reddo', 'dev/reddo', 'master' ] | |
paths: [ 'reddo/**', '.github/workflows/reddo.yaml' ] | |
pull_request: | |
types: [ 'opened', 'closed' ] | |
branches: [ 'reddo', 'master' ] | |
paths: [ 'reddo/**', '.github/workflows/reddo.yaml' ] | |
jobs: | |
TestReddo: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go: [ '1.13', '1.18', 'oldstable', 'stable' ] | |
name: Test reddo with Go ${{ matrix.go }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Go env | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ matrix.go }} | |
- name: Run tests | |
run: | | |
go version | |
cd ./reddo | |
go test -cover -coverprofile=../coverage_reddo.txt -timeout 9999s -v -count 1 -p 1 -bench=. ./ | |
cd .. | |
- name: Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
flags: reddo | |
name: reddo | |
ReleaseDryRun: | |
runs-on: ubuntu-latest | |
needs: [ 'TestReddo' ] | |
outputs: | |
RESULT: ${{ steps.semrelease.outputs.result }} | |
VERSION: ${{ steps.semrelease.outputs.releaseVersion }} | |
RELEASE_NOTES: ${{ steps.semrelease.outputs.releaseNotes }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Release (dry-run) | |
id: semrelease | |
uses: btnguyen2k/action-semrelease@v3 | |
with: | |
dry-run: true | |
auto-mode: true | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
tag-major-release: false | |
tag-minor-release: false | |
branches: reddo,dev/reddo | |
tag-prefix: 'reddo/v' | |
tag-only: true | |
path: 'reddo/' | |
Release: | |
runs-on: ubuntu-latest | |
if: | | |
github.event.pull_request.merged == true && | |
github.ref == 'refs/heads/reddo' | |
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 metadata | |
run: | | |
RESULT='${{ needs.ReleaseDryRun.outputs.RESULT }}' | |
VERSION='${{ needs.ReleaseDryRun.outputs.VERSION }}' | |
RELEASE_NOTES='${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}' | |
MODULE=reddo | |
echo "π Updating module metadata..." | |
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} | |
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: | | |
MODULE=reddo | |
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 ${MODULE}-v${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 ${MODULE}-v${VERSION}" | |
git push -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 reddo to master after releasing new version ${{ needs.Release.outputs.VERSION }}", | |
body: process['env']['RELEASE_NOTES'], | |
head: 'reddo', | |
base: 'master', | |
maintainer_can_modify: true, | |
}); | |
console.log('β Created PR: ', pr); |