TrainRun.jl/.github/workflows/release.yml

270 lines
10 KiB
YAML
Raw Normal View History

2022-06-05 21:49:42 +02:00
name: create new release
on:
workflow_dispatch:
inputs:
version:
2022-12-21 13:18:38 +01:00
description: "Version to register (without leading 'v' and semantic versioning schema, e.g. '1.0.1')"
2022-06-05 21:49:42 +02:00
required: true
jobs:
create_package:
name: "create package"
runs-on: ubuntu-latest
outputs:
previous_version: ${{ steps.version_test.outputs.previous_version }}
2022-06-05 21:49:42 +02:00
steps:
# 1. checkout the repo
- name: "checkout"
uses: actions/checkout@v3
# 2. test if provided version number fits in semantic versioning schema
- name: "test version number"
id: version_test
2022-06-05 21:49:42 +02:00
run: |
VERSION=${{ github.event.inputs.version }}
2022-12-21 13:18:38 +01:00
echo "check if version follows the semantic version pattern"
SEM_VER_REGEX="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$"
2022-06-05 21:49:42 +02:00
STATUS=0
2022-12-21 13:18:38 +01:00
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
2022-12-21 13:18:38 +01:00
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 )
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 )
2022-12-21 13:18:38 +01:00
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
2022-12-21 13:18:38 +01:00
if [[ $(($VERSION_MINOR - 1)) -eq PREVIOUS_VERSION_MINOR ]]; then
if [[ $VERSION_PATCH -ne 0 ]]; then
STATUS=1
fi
else
STATUS=1
fi
fi
else
2022-12-21 13:18:38 +01:00
if [[ $(($VERSION_MAJOR - 1)) -eq PREVIOUS_VERSION_MAJOR ]]; then
if [[ $VERSION_MINOR -ne 0 ]]; then
STATUS=1
fi
2022-12-21 13:18:38 +01:00
if [[ $VERSION_PATCH -ne 0 ]]; then
STATUS=1
fi
else
STATUS=1
fi
fi
2022-06-05 21:49:42 +02:00
if [ $STATUS = 1 ]; then
echo "Version $VERSION skipped steps from the previous version $PREVIOUS_VERSION and thus does not follow the semantic versioning schema."
2022-12-21 13:18:38 +01:00
echo "Please see https://semver.org/ for further information."
2022-06-05 21:49:42 +02:00
exit 1
fi
echo "::set-output name=previous_version::$(version_test deposition show prereserved $PREVIOUS_VERSION)"
2022-12-21 13:18:38 +01:00
# 3. create release note
- name: "create release note"
run: |
VERSION=${{ github.event.inputs.version }}
2022-12-21 13:18:38 +01:00
PREVIOUS_VERSION=${{ needs.create_package.outputs.previous_version }}
STATUS=0
echo "create release note"
TOP=$(grep -n "## \[Unreleased\]" CHANGELOG.md | cut -d: -f1)
2022-06-05 21:49:42 +02:00
TOP=$(( $TOP + 1 ))
2022-12-21 13:18:38 +01:00
BOTTOM=$(grep -n -m 1 "## Version \[$PREVIOUS_VERSION\]" CHANGELOG.md | cut -d: -f1)
BOTTOM=$(( $BOTTOM - 1 ))
2022-06-07 13:13:59 +02:00
awk "NR>$TOP&&NR<$BOTTOM" CHANGELOG.md > release-note-v$VERSION.md
2022-06-05 21:49:42 +02:00
sed -i -- "s/###/##/g" release-note-v$VERSION.md
2022-12-21 13:18:38 +01:00
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
2022-06-05 21:49:42 +02:00
# 4. Update zenodo metadata.json
- name: "Update zenodo metadata.json"
2022-06-05 21:49:42 +02:00
run: |
VERSION=${{ github.event.inputs.version }}
sed -i".backup" -e"s/\"version\": \"%%\[SCRIPT\]\"/\"version\": \"$VERSION\"/g" .github/zenodo/metadata.json
# 5. create release archive
2022-12-21 13:18:38 +01:00
- name: "create release archive"
uses: papeloto/action-zip@v1
2022-06-05 21:49:42 +02:00
with:
files: docs src test README.md LICENSE Project.toml
recursive: false
dest: TrainRuns.jl-v${{ github.event.inputs.version }}.zip
# 6. upload artifact to share it with other jobs
2022-06-05 21:49:42 +02:00
- uses: actions/upload-artifact@v3
with:
path: |
2022-06-07 15:22:51 +02:00
release-note-v${{ github.event.inputs.version }}.md
2022-06-05 21:49:42 +02:00
TrainRuns.jl-v${{ github.event.inputs.version }}.zip
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`
- uses: actions/upload-artifact@v3
with:
path: .github/zenodo/metadata.json
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`
publish_github:
needs: create_package
name: "publish on github"
runs-on: ubuntu-latest
steps:
# 1. download artifact in folder artifact/
- uses: actions/download-artifact@v3
# 2. creating a new release
- name: "create release"
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body_path: artifact/release-note-v${{ github.event.inputs.version }}.md
draft: false
prerelease: false
# 3. upload package to new release
- name: "upload release asset"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifact/TrainRuns.jl-v${{ github.event.inputs.version }}.zip
asset_name: TrainRuns.jl-v${{ github.event.inputs.version }}.zip
asset_content_type: application/zip
# 4. publish release on github
- name: "publish release"
uses: StuYarrow/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
id: ${{ steps.create_release.outputs.id }}
publish_zenodo:
needs: create_package
name: "publish on zenodo"
outputs:
doi: ${{ steps.zenodraft.outputs.doi }}
runs-on: ubuntu-latest
steps:
# 1. download artifact in folder artifact/ and move it one level up
- uses: actions/download-artifact@v3
- run: |
mv ./artifact/TrainRuns.jl-v${{ github.event.inputs.version }}.zip ./
# 2. install zenodraft
- name: "install zenodraft"
run: npm install -g zenodraft
# 3. upload new release to zenodo
- name: "uploading to zenodo"
id: zenodraft
env:
ZENODO_ACCESS_TOKEN: ${{ secrets.ZENODO_ACCESS_TOKEN }}
COLLECTION: 6448563
run: |
ID=$(zenodraft deposition create version $COLLECTION)
zenodraft file add $ID TrainRuns.jl-v*.zip
zenodraft metadata update $ID artifact/metadata.json
zenodraft deposition publish $ID
echo "::set-output name=doi::$(zenodraft deposition show prereserved $ID)"
update_repo:
needs: publish_zenodo
name: "updating CITATION.cff and CHANGELOG.md"
2022-06-05 21:49:42 +02:00
runs-on: ubuntu-latest
steps:
# 1. checkout the repo
- name: "checkout"
uses: actions/checkout@v3
# 2. update CITATION.cff
- name: "update CITATION.cff"
run: |
2022-06-05 21:49:42 +02:00
DATE=$(date "+%Y-%m-%d")
VERSION=${{ github.event.inputs.version }}
DOI=${{ needs.publish_zenodo.outputs.doi }}
2022-06-05 21:49:42 +02:00
echo "find lines in CITATION.cff"
2022-12-21 13:18:38 +01:00
VERSION_LINE=$(grep -n '^version:' CITATION.cff | cut -d: -f1)
2022-06-05 21:49:42 +02:00
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")
DOI_LINE=$(( $DOI_LINE + 1 ))
echo "update CITATION.cff"
sed -i -- "${VERSION_LINE}s|.*|version: $VERSION|" CITATION.cff
sed -i -- "${DATE_LINE}s|.*|date-released: ${DATE}|" CITATION.cff
sed -i -- "${DOI_LINE}s|.*| value: $DOI|" CITATION.cff
# 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 }}
2022-12-21 13:18:38 +01:00
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
# 4. push the change back to main
2022-06-05 21:49:42 +02:00
- name: push
2022-12-19 22:02:19 +01:00
uses: EndBug/add-and-commit@v9
2022-06-05 21:49:42 +02:00
with:
message: "DOI updated to ${{ github.event.inputs.version }} (via github action)"
add: CITATION.cff CHANGELOG.md
2022-12-19 22:02:19 +01:00
author_name: railtoolkit
author_email: railtoolkit@ownx.net
2022-06-05 21:49:42 +02:00
register:
needs: update_repo
name: "publish in JuliaRegistries"
runs-on: ubuntu-latest
steps:
# 1. register new release at JuliaRegistries
- uses: julia-actions/RegisterAction@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
2022-12-19 22:02:19 +01:00
publish_mastodon:
needs: publish_zenodo
2022-12-19 22:02:19 +01:00
name: "Send toot about it to railtoolkit@fosstodon.org"
2022-06-05 21:49:42 +02:00
runs-on: ubuntu-latest
2022-12-19 22:02:19 +01:00
steps:
- uses: cbrgm/mastodon-github-action@v1
with:
message: "The new version ${{ github.event.inputs.version }} of TrainRuns.jl is available! DOI: https://doi.org/${{needs.publish_zenodo.outputs.doi}}"
visibility: "public" # default: public
env:
MASTODON_URL: "https://fosstodon.org/"
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }} # access token