Skip to content

g18

g18 #61

Workflow file for this run

name: g18
on:
push:
branches: [ 'g18', 'dev/g18', 'master' ]
paths: [ 'g18/**', '.github/workflows/g18.yaml' ]
pull_request:
types: [ 'opened', 'closed' ]
branches: [ 'g18', 'master' ]
paths: [ 'g18/**', '.github/workflows/g18.yaml' ]
schedule:
# run once every month (at 00:00 UTC) to make sure the lib works with latest version of Go
- cron: '0 0 1 * *'
jobs:
TestG18:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.18', 'oldstable', 'stable' ]
name: Test g18 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 ./g18
go test -cover -coverprofile=../coverage_g18.txt -v -count 1 -p 1 ./
cd ..
- name: Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
flags: g18
name: g18
ReleaseDryRun:
runs-on: ubuntu-latest
needs: [ 'TestG18' ]
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: g18,dev/g18
tag-prefix: 'g18/v'
tag-only: true
path: 'g18/'
Release:
runs-on: ubuntu-latest
if: |
github.event.pull_request.merged == true &&
github.ref == 'refs/heads/g18'
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=g18
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 files ==========
sed -i -E "s/<<VERSION>>/v${VERSION}/" ${MODULE}/*.go
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 g18 to master after releasing new version ${{ needs.Release.outputs.VERSION }}",
body: process['env']['RELEASE_NOTES'],
head: 'g18',
base: 'master',
maintainer_can_modify: true,
});
console.log('✅ Created PR: ', pr);