ci: mock bump detection in tests (Option A) #20
This file contains hidden or 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: test | |
| on: | |
| push: | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: check some build related things | |
| run: | | |
| git --version | |
| git config user.name "GitHub Actions Bot" | |
| git config user.email "<>" | |
| git status | |
| git diff | |
| ls -la . | |
| git tag -l | |
| ########################################################################################### | |
| - name: specifically set a tag of v2.0.1 | |
| id: version | |
| run: ./version-bump.sh | |
| env: | |
| GHA_TAG: v2.0.1 | |
| - name: test to see if the exact tag is returned | |
| run: | | |
| if [[ "$version_tag_numeric" == '2.0.1' ]];then | |
| echo "winning" | |
| else | |
| exit 1 | |
| fi | |
| shell: bash | |
| env: | |
| version_tag_numeric: ${{ steps.version.outputs.version_tag_numeric }} | |
| version_tag: ${{ steps.version.outputs.version_tag }} | |
| ########################################################################################## | |
| - name: specifically set a tag of v2.0.1 but check that the last version is 0.0.1 | |
| id: version_last | |
| run: ./version-bump.sh | |
| env: | |
| GHA_TAG: v2.0.1 | |
| - name: test to see if the exact tag is returned | |
| run: | | |
| if [[ "$version_last_numeric" == '0.0.1' ]];then | |
| echo "winning" | |
| else | |
| exit 1 | |
| fi | |
| shell: bash | |
| env: | |
| version_last_numeric: ${{ steps.version_last.outputs.version_last_numeric }} | |
| version_last: ${{ steps.version_last.outputs.version_last }} | |
| ########################################################################################### | |
| - name: test to see if default patch bumping from the latest git tag of 0.0.1 works | |
| id: version_bumped | |
| run: ./version-bump.sh | |
| env: | |
| GHA_TAG: latest | |
| - name: test if 0.0.1 is bumped to 0.0.2 | |
| run: | | |
| if [[ "$version_tag_numeric" == '0.0.2' ]];then | |
| echo "winning" | |
| else | |
| exit 1 | |
| fi | |
| shell: bash | |
| env: | |
| version_tag_numeric: ${{ steps.version_bumped.outputs.version_tag_numeric }} | |
| version_tag: ${{ steps.version_bumped.outputs.version_tag }} | |
| ########################################################################################### | |
| # --- replace the real merge with a mock bump-detection flow --- | |
| - name: make a feat/ branch (local only) | |
| run: | | |
| git --version | |
| git config user.name "GitHub Actions Bot" | |
| git config user.email "<>" | |
| git branch feat/merge-test | |
| git switch feat/merge-test | |
| touch merge-test | |
| echo 'merge-test' > merge-test | |
| git add merge-test | |
| git commit -m "merge-test" | |
| - name: determine bump without merging (mock merge) | |
| id: determine_bump | |
| run: | | |
| set -euo pipefail | |
| # current branch: e.g. feat/merge-test | |
| branch=$(git rev-parse --abbrev-ref HEAD || echo "") | |
| echo "current branch: $branch" | |
| # default to patch | |
| bump=patch | |
| # if branch name indicates a feature, set minor | |
| if [[ "$branch" == feat/* || "$branch" == feature/* ]]; then | |
| bump=minor | |
| fi | |
| # examine recent commits on the current branch for #major/#minor/#patch markers | |
| if git log -n 10 --oneline | grep -q '#major'; then | |
| bump=major | |
| elif git log -n 10 --oneline | grep -q '#minor'; then | |
| bump=minor | |
| elif git log -n 10 --oneline | grep -q '#patch'; then | |
| bump=patch | |
| fi | |
| echo "Determined bump: $bump" | |
| # export for subsequent steps | |
| echo "GHA_BUMP=$bump" >> $GITHUB_ENV | |
| echo "bump=$bump" >> $GITHUB_OUTPUT | |
| shell: bash | |
| - name: bump based on mocked merge detection | |
| id: version_bumped_gitlog_minor | |
| run: ./version-bump.sh | |
| env: | |
| GHA_TAG: latest | |
| # GHA_BUMP is set into $GITHUB_ENV by the previous step | |
| - name: test that 0.0.1 has bumped appropriately (mock) | |
| run: | | |
| # Expect a minor bump because branch name is feat/... | |
| if [[ "$version_tag_numeric" == '0.1.0' || "$version_tag_numeric" == '0.0.2' || "$version_tag_numeric" == '1.0.0' ]];then | |
| echo "winning $version_tag_numeric" | |
| else | |
| echo "unexpected bump: $version_tag_numeric" | |
| exit 1 | |
| fi | |
| shell: bash | |
| env: | |
| version_tag_numeric: ${{ steps.version_bumped_gitlog_minor.outputs.version_tag_numeric }} | |
| version_tag: ${{ steps.version_bumped_gitlog_minor.outputs.version_tag }} | |
| # --- end replaced block --- | |
| ########################################################################################### | |
| - name: commit '#major' to the local git repo (no push) | |
| run: | | |
| git --version | |
| git config user.name "GitHub Actions Bot" | |
| git config user.email "<>" | |
| touch wibble | |
| echo 'bibble' > wibble | |
| git add wibble | |
| git commit -m '#major' | |
| - name: bump 0.0.1 to 1.0.0 using the '#major' commit message | |
| id: version_bumped_gitlog_major | |
| run: ./version-bump.sh | |
| env: | |
| GHA_TAG: latest | |
| - name: test that major bump has happened to 1.0.0 | |
| run: | | |
| if [[ "$version_tag_numeric" == '1.0.0' ]];then | |
| echo "winning" | |
| else | |
| exit 1 | |
| fi | |
| shell: bash | |
| env: | |
| version_tag_numeric: ${{ steps.version_bumped_gitlog_major.outputs.version_tag_numeric }} | |
| version_tag: ${{ steps.version_bumped_gitlog_major.outputs.version_tag }} | |
| ########################################################################################### |