Skip to content

Commit

Permalink
sync fork
Browse files Browse the repository at this point in the history
* pre_release is 'false' by default now. So no change needed any more
  • Loading branch information
andreasparteli committed Nov 6, 2023
2 parents 7af9900 + a2c70ae commit a19e878
Show file tree
Hide file tree
Showing 10 changed files with 788 additions and 130 deletions.
19 changes: 19 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--- Provide a general summary of your changes in the Title above -->
<!--- See [CONTRIBUTING.md](CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md). -->
# Summary of changes

<!--- Describe your changes -->

## Breaking Changes

Do any of the included changes break current behaviour or configuration?

(**YES** / NO)

## How changes have been tested

-

## List any unknowns

-
54 changes: 54 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Lint

on:
pull_request:
types:
- opened
- edited
- reopened
- synchronize

permissions:
pull-requests: write
checks: write
contents: read

jobs:
lint-bash:
name: Lint Bash scripts
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: reviewdog/action-shellcheck@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review
level: warning
path: .
pattern: '*.sh'
fail_on_error: true

lint-dockerfile:
name: Lint Dockerfiles
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: hadolint
uses: reviewdog/action-hadolint@v1
with:
reporter: github-pr-review
level: warning
fail_on_error: true
hadolint_ignore: DL3016 DL3018 # Ignore pinning apk and npm packages to specific version with @

lint-actions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Lint Github Actions
uses: reviewdog/action-actionlint@v1
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
reporter: github-pr-review
60 changes: 50 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,56 @@
name: Bump version

on:
push:
pull_request:
types:
- closed
branches:
- master
paths:
- 'entrypoint.sh'
- 'action.yml'
- 'Dockerfile'

jobs:
build:
runs-on: ubuntu-latest
bump-version:
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- uses: actions/checkout@master
with:
fetch-depth: '0'
- name: Bump version and push tag
uses: anothrNick/github-tag-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v3
with:
fetch-depth: '0'

- name: version-tag
id: tag
uses: anothrNick/github-tag-action@master # if we use 1 there is a too-be-fixed bug https://github.com/anothrNick/github-tag-action/actions/runs/3139501775/jobs/5099976842#step:1:35 as alternative we could use v1
env:
VERBOSE: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_API_TAGGING: false # uses git cli

# auto releases is not working atm and is deleting releases due branch tags
- name: automatic-draft-release
uses: marvinpinto/[email protected]
with:
draft: true
repo_token: ${{ secrets.GITHUB_TOKEN }}
title: "${{ steps.tag.outputs.tag }}: [title-edit-me] by:${{ github.actor }}"
automatic_release_tag: ${{ steps.tag.outputs.new_tag }}

- name: version-tag-major
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git fetch --tags
tagFmt="^v?[0-9]+\.[0-9]+\.[0-9]+$"
tag="$(git for-each-ref --sort=-v:refname --format '%(refname:lstrip=2)' | grep -E "$tagFmt" | head -n 1)"
[[ "$tag" =~ ^([0-9]+) ]] # use ^(v[0-9]+) for vX
major=${BASH_REMATCH[1]}
# update major tag
git tag -f "$major"
git push -f origin "$major"
# add vX as 1 is linked to short sha bug https://github.com/anothrNick/github-tag-action/actions/runs/3139501775/jobs/5099976842#step:1:35
git tag -f "v$major"
git push -f origin "v$major"
204 changes: 204 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
name: Test
# This workflow tests the tag action and can be used on PRs to detect (some) breaking changes.

on:
workflow_dispatch:
pull_request:
types:
- opened
- edited
- reopened
- synchronize

permissions:
pull-requests: write
checks: write
contents: read

jobs:
test-action:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: '0'

# Use the action to generate a tag for itself
- name: Test action main1 (with_v true)
id: test_main1
uses: ./
env:
DRY_RUN: true
WITH_V: true
VERBOSE: true
DEFAULT_BUMP: minor # default
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test action main2 (with_v false)
id: test_main2
uses: ./
env:
DRY_RUN: true
WITH_V: false
VERBOSE: true
DEFAULT_BUMP: major
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test action main3 (with_v false)
id: test_main3
uses: ./
env:
DRY_RUN: true
WITH_V: false
VERBOSE: true
DEFAULT_BUMP: none
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test action main4 (with_v true)
id: test_main4
uses: ./
env:
DRY_RUN: true
WITH_V: true
VERBOSE: true
DEFAULT_BUMP: none
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test action main5 (with_v true)
id: test_main5
uses: ./
env:
DRY_RUN: true
WITH_V: true
VERBOSE: true
DEFAULT_BUMP: patch
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Use the action to generate a tag for itself
- name: Test action pre1-release (with_v true)
id: test_pre1
uses: ./
env:
DRY_RUN: true
WITH_V: true
PRERELEASE: true
PRERELEASE_SUFFIX: test
VERBOSE: true
DEFAULT_BUMP: minor # default
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test action pre2-release (with_v false)
id: test_pre2
uses: ./
env:
DRY_RUN: true
WITH_V: false
PRERELEASE: true
PRERELEASE_SUFFIX: test
VERBOSE: true
DEFAULT_BUMP: major
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Check if the action created the expected output
- name: Check if the tag would have been created
shell: bash
run: |
set -x
MAIN1_OUTPUT_TAG=${{ steps.test_main1.outputs.old_tag }}
MAIN1_OUTPUT_NEWTAG=${{ steps.test_main1.outputs.new_tag }}
MAIN1_OUTPUT_PART=${{ steps.test_main1.outputs.part }}
PRE1_OUTPUT_TAG=${{ steps.test_pre1.outputs.old_tag }}
PRE1_OUTPUT_NEWTAG=${{ steps.test_pre1.outputs.new_tag }}
PRE1_OUTPUT_PART=${{ steps.test_pre1.outputs.part }}
MAIN2_OUTPUT_TAG=${{ steps.test_main2.outputs.old_tag }}
MAIN2_OUTPUT_NEWTAG=${{ steps.test_main2.outputs.new_tag }}
MAIN2_OUTPUT_PART=${{ steps.test_main2.outputs.part }}
PRE2_OUTPUT_TAG=${{ steps.test_pre2.outputs.old_tag }}
PRE2_OUTPUT_NEWTAG=${{ steps.test_pre2.outputs.new_tag }}
PRE2_OUTPUT_PART=${{ steps.test_pre2.outputs.part }}
MAIN3_OUTPUT_TAG=${{ steps.test_main3.outputs.old_tag }}
MAIN3_OUTPUT_NEWTAG=${{ steps.test_main3.outputs.new_tag }}
MAIN3_OUTPUT_PART=${{ steps.test_main3.outputs.part }}
MAIN4_OUTPUT_TAG=${{ steps.test_main4.outputs.old_tag }}
MAIN4_OUTPUT_NEWTAG=${{ steps.test_main4.outputs.new_tag }}
MAIN4_OUTPUT_PART=${{ steps.test_main4.outputs.part }}
MAIN5_OUTPUT_TAG=${{ steps.test_main5.outputs.old_tag }}
MAIN5_OUTPUT_NEWTAG=${{ steps.test_main5.outputs.new_tag }}
MAIN5_OUTPUT_PART=${{ steps.test_main5.outputs.part }}
echo -e "> MAIN tests with_v, default bump:\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN1 with_v Tag: $MAIN1_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN1 with_v New tag: $MAIN1_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN1 with_v Part: $MAIN1_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> Pre-release tests with_v, default bump:\n" >> $GITHUB_STEP_SUMMARY
echo "PRE1 with_v Tag: $PRE1_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "PRE1 with_v New tag: $PRE1_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "PRE1 with_v Part: $PRE1_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> MAIN tests without_v, bump major:\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN2 without_v Tag: $MAIN2_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN2 without_v New tag: $MAIN2_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN2 without_v Part: $MAIN2_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> Pre-release tests without_v, bump major:\n" >> $GITHUB_STEP_SUMMARY
echo "PRE2 without_v Tag: $PRE2_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "PRE2 without_v New tag: $PRE2_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "PRE2 without_v Part: $PRE2_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> MAIN tests without_v, bump none: (should be the same old tag no change regardless of what original tag contains or not v)\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN3 without_v Tag: $MAIN3_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN3 without_v New tag: $MAIN3_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN3 without_v Part: $MAIN3_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> MAIN tests with_v, bump none: (should be the same old tag no change regardless of what original tag contains or not v)\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN4 with_v Tag: $MAIN4_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN4 with_v New tag: $MAIN4_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN4 with_v Part: $MAIN4_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
echo -e "> MAIN tests with_v, bump patch:\n" >> $GITHUB_STEP_SUMMARY
echo "MAIN5 with_v Tag: $MAIN5_OUTPUT_TAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN5 with_v New tag: $MAIN5_OUTPUT_NEWTAG" >> $GITHUB_STEP_SUMMARY
echo "MAIN5 with_v Part: $MAIN5_OUTPUT_PART" >> $GITHUB_STEP_SUMMARY
# check that the original tag got bumped either major, minor, patch
verlte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
verlt() {
[ "$1" = "$2" ] && return 1 || verlte $1 $2
}
# needs to be a greater tag in default minor
main1="$(verlt $MAIN1_OUTPUT_TAG $MAIN1_OUTPUT_NEWTAG && true || false)"
pre1="$(verlt $PRE1_OUTPUT_TAG $PRE1_OUTPUT_NEWTAG && true || false)"
# needs to be a greater tag in bump major
main2="$(verlt $MAIN2_OUTPUT_TAG $MAIN2_OUTPUT_NEWTAG && true || false)"
pre2="$(verlt $PRE2_OUTPUT_TAG $PRE2_OUTPUT_NEWTAG && true || false)"
# needs to be the latest tag of the repo when bump is none
main3="$([ "$MAIN3_OUTPUT_TAG" = "$MAIN3_OUTPUT_NEWTAG" ] && true || false)"
main4="$([ "$MAIN4_OUTPUT_TAG" = "$MAIN4_OUTPUT_NEWTAG" ] && true || false)"
# needs to be a greater tag in bump patch
main5="$(verlt $MAIN5_OUTPUT_TAG $MAIN5_OUTPUT_NEWTAG && true || false)"
if $main1 && $pre1 && $main2 && $pre2 && $main3 && $main4 && $main5
then
echo -e "\n>>>>The tags were created correctly" >> $GITHUB_STEP_SUMMARY
else
echo -e "\n>>>>Tags NOT created correctly" >> $GITHUB_STEP_SUMMARY
exit 1
fi
Loading

0 comments on commit a19e878

Please sign in to comment.