From e8e9df9877162318c74f131cdd99d8cabccc4201 Mon Sep 17 00:00:00 2001 From: Martin Scheidt Date: Tue, 20 Dec 2022 19:20:40 +0100 Subject: [PATCH 1/3] debug action --- .github/workflows/debug.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/debug.yml diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml new file mode 100644 index 0000000..7404d5e --- /dev/null +++ b/.github/workflows/debug.yml @@ -0,0 +1,32 @@ +### github action to publish a debug +## +name: "debug" + +## Controls when the workflow will run +on: + push: + branches: [ github-action ] + + ## Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +## A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + debug: + # needs: create_package + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - name: "checkout" + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + uses: actions/checkout@v3 + + ## opening a debug console + - name: Setup upterm session + env: + ZENODO_SANDBOX_ACCESS_TOKEN: ${{ secrets.ZENODO_SANDBOX_ACCESS_TOKEN }} + uses: lhotari/action-upterm@v1 + with: + limit-access-to-actor: true From e754220e795c30200fb8a0d4c261e89d807e3a42 Mon Sep 17 00:00:00 2001 From: Martin Scheidt Date: Tue, 20 Dec 2022 23:04:20 +0100 Subject: [PATCH 2/3] added automatic version bump for CHANGELOG.md --- .github/workflows/release.yml | 95 ++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 18 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5bc96b8..15aa00c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,24 +11,71 @@ jobs: create_package: name: "create package" runs-on: ubuntu-latest + outputs: + previous_version: ${{ steps.version_test.outputs.previous_version }} steps: # 1. checkout the repo - name: "checkout" uses: actions/checkout@v3 - # 2. create release notes - - name: "create release notes" + # 2. test if provided version number fits in semantic versioning schema + - name: "test version number" + id: version_test run: | VERSION=${{ github.event.inputs.version }} STATUS=0 - grep -qs "Version \[$VERSION\]" CHANGELOG.md || STATUS=1 + grep -qs "Version \[$VERSION\]" CHANGELOG.md && STATUS=1 if [ $STATUS = 1 ]; then - echo "Version $VERSION is not present in CHANGELOG.md." + echo "Version $VERSION is already present in CHANGELOG.md." exit 1 fi - TOP=$(grep -n "Version \[$VERSION\]" CHANGELOG.md | cut -d: -f1) + VERSION_MAJOR=$(echo $VERSION | cut -d. -f1 ) + VERSION_MINOR=$(echo $VERSION | cut -d. -f2 ) + VERSION_PATCH=$(echo $VERSION | cut -d. -f3 ) + PREVIOUS_VERSION=$(grep -n -m 1 "## Version \[*.*.*\]" CHANGELOG.md | cut -d[ -f2 | cut -d] -f1) + PREVIOUS_VERSION_MAJOR=$(echo $PREVIOUS_VERSION | cut -d. -f1 ) + PREVIOUS_VERSION_MINOR=$(echo $PREVIOUS_VERSION | cut -d. -f2 ) + PREVIOUS_VERSION_PATCH=$(echo $PREVIOUS_VERSION | cut -d. -f3 ) + if [ $VERSION_MAJOR = PREVIOUS_VERSION_MAJOR ]; then + if [ $VERSION_MINOR = PREVIOUS_VERSION_MINOR ]; then + if [[ $(($VERSION_PATCH - 1)) -ne PREVIOUS_VERSION_PATCH ]]; then + STATUS=1 + fi + else + if [[ $(($VERSION_MINOR - 1)) = PREVIOUS_VERSION_MINOR ]]; then + if [ $VERSION_PATCH -ne 0 ]; then + STATUS=1 + fi + else + STATUS=1 + fi + fi + else + if [[ $(($VERSION_MAJOR - 1)) = PREVIOUS_VERSION_MAJOR ]]; then + if [ $VERSION_MINOR -ne 0 ]; then + STATUS=1 + fi + if [ $VERSION_PATCH -ne 0 ]; then + STATUS=1 + fi + else + STATUS=1 + fi + fi + if [ $STATUS = 1 ]; then + echo "Version $VERSION skipped steps from the previous version $PREVIOUS_VERSION and thus does not follow the semantic versioning schema." + echo "Please see https://semver.org/spec/v2.0.0.html for further information." + exit 1 + fi + echo "::set-output name=previous_version::$(version_test deposition show prereserved $PREVIOUS_VERSION)" + + # 3. create release notes + - name: "create release notes" + run: | + VERSION=${{ github.event.inputs.version }} + TOP=$(grep -n "## \[Unreleased\]" CHANGELOG.md | cut -d: -f1) awk "NR>$TOP" CHANGELOG.md > release-note.tmp.md - BOTTOM=$(grep -n -m 1 "## Version\|[Unreleased]:" release-note.tmp.md | cut -d: -f1) + BOTTOM=$(grep -n -m 1 "## Version \[*.*.*\]" release-note.tmp.md | cut -d: -f1) BOTTOM=$(( $TOP + $BOTTOM )) BOTTOM=$(( $BOTTOM - 2 )) TOP=$(( $TOP + 1 )) @@ -36,20 +83,20 @@ jobs: sed -i -- "s/###/##/g" release-note-v$VERSION.md rm release-note.tmp.md - # 3. Update metadata.json - - name: "Update metadata.json" + # 4. Update zenodo metadata.json + - name: "Update zenodo metadata.json" run: | VERSION=${{ github.event.inputs.version }} sed -i".backup" -e"s/\"version\": \"%%\[SCRIPT\]\"/\"version\": \"$VERSION\"/g" .github/zenodo/metadata.json - # 4. create release archive + # 5. create release archive - uses: papeloto/action-zip@v1 with: files: docs src test README.md LICENSE Project.toml recursive: false dest: TrainRuns.jl-v${{ github.event.inputs.version }}.zip - # 5. upload artifact to share it with other jobs + # 6. upload artifact to share it with other jobs - uses: actions/upload-artifact@v3 with: path: | @@ -130,9 +177,9 @@ jobs: zenodraft deposition publish $ID echo "::set-output name=doi::$(zenodraft deposition show prereserved $ID)" - update_citation: + update_repo: needs: publish_zenodo - name: "updating CITATION.cff" + name: "updating CITATION.cff and CHANGELOG.md" runs-on: ubuntu-latest steps: # 1. checkout the repo @@ -140,10 +187,11 @@ jobs: uses: actions/checkout@v3 # 2. update CITATION.cff - - run: | + - name: "update CITATION.cff" + run: | DATE=$(date "+%Y-%m-%d") VERSION=${{ github.event.inputs.version }} - DOI=${{needs.publish_zenodo.outputs.doi}} + DOI=${{ needs.publish_zenodo.outputs.doi }} echo "find lines in CITATION.cff" VERSION_LINE=$(grep -n 'version: [0-9][0-9][0-9][0-9].[0-1][0-9]' CITATION.cff | cut -d: -f1) DATE_LINE=$(grep -n 'date-released:' CITATION.cff | cut -d: -f1) @@ -155,17 +203,28 @@ jobs: sed -i -- "${DATE_LINE}s|.*|date-released: ${DATE}|" CITATION.cff sed -i -- "${DOI_LINE}s|.*| value: $DOI|" CITATION.cff - # 3. push the change back to main + # 3. update CHANGELOG.md + - name: "update CHANGELOG.md" + run: | + DATE=$(date "+%Y-%m-%d") + VERSION=${{ github.event.inputs.version }} + URL="https://github.com/railtoolkit/TrainRuns.jl/compare" + PREVIOUS_VERSION=${{ needs.create_package.outputs.previous_version }} + echo "update CHANGELOG.md" + sed -i -- "/## \[Unreleased\]/a\\\n\n## Version [$VERSION] $DATE" CHANGELOG.md + sed -i -- "s|^\[Unreleased\]: .*$|\[Unreleased\]: $URL/v$VERSION...main\n\[$VERSION\]: $URL/v$PREVIOUS_VERSION...v$VERSION|" CHANGELOG.md + + # 4. push the change back to main - name: push uses: EndBug/add-and-commit@v9 with: - message: "DOI updated to ${{needs.create_package.outputs.version}} (via github action)" - add: CITATION.cff + message: "DOI updated to ${{ github.event.inputs.version }} (via github action)" + add: CITATION.cff CHANGELOG.md author_name: railtoolkit author_email: railtoolkit@ownx.net register: - needs: update_citation + needs: update_repo name: "publish in JuliaRegistries" runs-on: ubuntu-latest steps: From dc8c7c8f5e4999cdc2199269192e2849a4e1b25d Mon Sep 17 00:00:00 2001 From: Martin Scheidt Date: Wed, 21 Dec 2022 13:18:38 +0100 Subject: [PATCH 3/3] added semantic versioning checking --- .github/workflows/release.yml | 60 ++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 15aa00c..33f64f3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: version: - description: "Version to register or component to bump (without leading 'v' e.g. '1.0.1')" + description: "Version to register (without leading 'v' and semantic versioning schema, e.g. '1.0.1')" required: true jobs: @@ -23,12 +23,24 @@ jobs: id: version_test run: | VERSION=${{ github.event.inputs.version }} + echo "check if version follows the semantic version pattern" + SEM_VER_REGEX="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$" STATUS=0 + if [[ ! $VERSION =~ $SEM_VER_REGEX ]]; then + STATUS=1 + fi + if [ $STATUS = 1 ]; then + echo "Version $VERSION does not follow the semantic versioning schema." + echo "Please see https://semver.org/ for further information." + exit 1 + fi + echo "check if version was already used" grep -qs "Version \[$VERSION\]" CHANGELOG.md && STATUS=1 if [ $STATUS = 1 ]; then echo "Version $VERSION is already present in CHANGELOG.md." exit 1 fi + echo "check if version is an increment" VERSION_MAJOR=$(echo $VERSION | cut -d. -f1 ) VERSION_MINOR=$(echo $VERSION | cut -d. -f2 ) VERSION_PATCH=$(echo $VERSION | cut -d. -f3 ) @@ -36,14 +48,14 @@ jobs: PREVIOUS_VERSION_MAJOR=$(echo $PREVIOUS_VERSION | cut -d. -f1 ) PREVIOUS_VERSION_MINOR=$(echo $PREVIOUS_VERSION | cut -d. -f2 ) PREVIOUS_VERSION_PATCH=$(echo $PREVIOUS_VERSION | cut -d. -f3 ) - if [ $VERSION_MAJOR = PREVIOUS_VERSION_MAJOR ]; then - if [ $VERSION_MINOR = PREVIOUS_VERSION_MINOR ]; then + if [[ $VERSION_MAJOR -eq PREVIOUS_VERSION_MAJOR ]]; then + if [[ $VERSION_MINOR -eq PREVIOUS_VERSION_MINOR ]]; then if [[ $(($VERSION_PATCH - 1)) -ne PREVIOUS_VERSION_PATCH ]]; then STATUS=1 fi else - if [[ $(($VERSION_MINOR - 1)) = PREVIOUS_VERSION_MINOR ]]; then - if [ $VERSION_PATCH -ne 0 ]; then + if [[ $(($VERSION_MINOR - 1)) -eq PREVIOUS_VERSION_MINOR ]]; then + if [[ $VERSION_PATCH -ne 0 ]]; then STATUS=1 fi else @@ -51,11 +63,11 @@ jobs: fi fi else - if [[ $(($VERSION_MAJOR - 1)) = PREVIOUS_VERSION_MAJOR ]]; then - if [ $VERSION_MINOR -ne 0 ]; then + if [[ $(($VERSION_MAJOR - 1)) -eq PREVIOUS_VERSION_MAJOR ]]; then + if [[ $VERSION_MINOR -ne 0 ]]; then STATUS=1 fi - if [ $VERSION_PATCH -ne 0 ]; then + if [[ $VERSION_PATCH -ne 0 ]]; then STATUS=1 fi else @@ -64,24 +76,33 @@ jobs: fi if [ $STATUS = 1 ]; then echo "Version $VERSION skipped steps from the previous version $PREVIOUS_VERSION and thus does not follow the semantic versioning schema." - echo "Please see https://semver.org/spec/v2.0.0.html for further information." + echo "Please see https://semver.org/ for further information." exit 1 fi echo "::set-output name=previous_version::$(version_test deposition show prereserved $PREVIOUS_VERSION)" - # 3. create release notes - - name: "create release notes" + # 3. create release note + - name: "create release note" run: | VERSION=${{ github.event.inputs.version }} + PREVIOUS_VERSION=${{ needs.create_package.outputs.previous_version }} + STATUS=0 + echo "create release note" TOP=$(grep -n "## \[Unreleased\]" CHANGELOG.md | cut -d: -f1) - awk "NR>$TOP" CHANGELOG.md > release-note.tmp.md - BOTTOM=$(grep -n -m 1 "## Version \[*.*.*\]" release-note.tmp.md | cut -d: -f1) - BOTTOM=$(( $TOP + $BOTTOM )) - BOTTOM=$(( $BOTTOM - 2 )) TOP=$(( $TOP + 1 )) + BOTTOM=$(grep -n -m 1 "## Version \[$PREVIOUS_VERSION\]" CHANGELOG.md | cut -d: -f1) + BOTTOM=$(( $BOTTOM - 1 )) awk "NR>$TOP&&NR<$BOTTOM" CHANGELOG.md > release-note-v$VERSION.md sed -i -- "s/###/##/g" release-note-v$VERSION.md - rm release-note.tmp.md + echo "check if release note is empty" + WORD_COUNT=$(wc -w release-note-v$VERSION.md | awk '{print $1}') + if [[ $WORD_COUNT -lt 4 ]]; then + STATUS=1 + fi + if [ $STATUS = 1 ]; then + echo "Please provide a meaningful CHANGELOG.md for the new version $VERSION" + exit 1 + fi # 4. Update zenodo metadata.json - name: "Update zenodo metadata.json" @@ -90,7 +111,8 @@ jobs: sed -i".backup" -e"s/\"version\": \"%%\[SCRIPT\]\"/\"version\": \"$VERSION\"/g" .github/zenodo/metadata.json # 5. create release archive - - uses: papeloto/action-zip@v1 + - name: "create release archive" + uses: papeloto/action-zip@v1 with: files: docs src test README.md LICENSE Project.toml recursive: false @@ -193,7 +215,7 @@ jobs: VERSION=${{ github.event.inputs.version }} DOI=${{ needs.publish_zenodo.outputs.doi }} echo "find lines in CITATION.cff" - VERSION_LINE=$(grep -n 'version: [0-9][0-9][0-9][0-9].[0-1][0-9]' CITATION.cff | cut -d: -f1) + VERSION_LINE=$(grep -n '^version:' CITATION.cff | cut -d: -f1) DATE_LINE=$(grep -n 'date-released:' CITATION.cff | cut -d: -f1) echo "select the second DOI" DOI_LINE=$(grep -n 'type: doi' CITATION.cff | cut -d: -f1 | awk "NR==2") @@ -210,7 +232,7 @@ jobs: VERSION=${{ github.event.inputs.version }} URL="https://github.com/railtoolkit/TrainRuns.jl/compare" PREVIOUS_VERSION=${{ needs.create_package.outputs.previous_version }} - echo "update CHANGELOG.md" + echo "increment CHANGELOG.md" sed -i -- "/## \[Unreleased\]/a\\\n\n## Version [$VERSION] $DATE" CHANGELOG.md sed -i -- "s|^\[Unreleased\]: .*$|\[Unreleased\]: $URL/v$VERSION...main\n\[$VERSION\]: $URL/v$PREVIOUS_VERSION...v$VERSION|" CHANGELOG.md