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

333 lines
14 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-24 17:29:55 +01:00
description: "Version to register (semantic versioning schema, e.g. '1.0.1'):"
2022-06-05 21:49:42 +02:00
required: true
jobs:
2022-12-24 17:29:55 +01:00
version:
2022-12-30 19:02:57 +01:00
name: "check submitted version"
2022-06-05 21:49:42 +02:00
runs-on: ubuntu-latest
outputs:
2022-12-24 17:29:55 +01:00
current: ${{ steps.version_check.outputs.current }}
new: ${{ steps.version_check.outputs.new }}
2022-06-05 21:49:42 +02:00
steps:
- name: "checkout"
uses: actions/checkout@v3
2022-12-24 17:29:55 +01:00
- name: "check version number"
id: version_check
2022-06-05 21:49:42 +02:00
run: |
VERSION=${{ github.event.inputs.version }}
2022-12-24 17:29:55 +01:00
echo "Version to register '$VERSION':" >> $GITHUB_STEP_SUMMARY
## =================================
## check if version follows the semantic version pattern
## ---------------------------------
#remove a trailing 'v' if it exists
if [[ ${VERSION:0:1} -eq "v" ]]; then
VERSION=${VERSION:1}
fi
# check with regular expressions
2022-12-21 13:18:38 +01:00
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
2022-12-24 17:29:55 +01:00
echo "- :no_entry_sign: format does not follow the semantic versioning schema" >> $GITHUB_STEP_SUMMARY
echo ":warning: Please see https://semver.org/ for further information." >> $GITHUB_STEP_SUMMARY
exit 1
2022-12-24 17:29:55 +01:00
else
2022-12-30 19:02:57 +01:00
echo "- follows the semantic versioning schema format :white_check_mark:" >> $GITHUB_STEP_SUMMARY
fi
2022-12-24 17:29:55 +01:00
## =================================
## 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 )
2022-12-24 17:29:55 +01:00
CURRENT_VERSION=$(grep -n -m 1 "## Version \[*.*.*\]" CHANGELOG.md | cut -d[ -f2 | cut -d] -f1)
CURRENT_VERSION_MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1 )
CURRENT_VERSION_MINOR=$(echo $CURRENT_VERSION | cut -d. -f2 )
CURRENT_VERSION_PATCH=$(echo $CURRENT_VERSION | cut -d. -f3 )
if [[ $VERSION_MAJOR -eq CURRENT_VERSION_MAJOR ]]; then
if [[ $VERSION_MINOR -eq CURRENT_VERSION_MINOR ]]; then
if [[ $(($VERSION_PATCH - 1)) -ne CURRENT_VERSION_PATCH ]]; then
STATUS=1
fi
else
2022-12-24 17:29:55 +01:00
if [[ $(($VERSION_MINOR - 1)) -eq CURRENT_VERSION_MINOR ]]; then
2022-12-21 13:18:38 +01:00
if [[ $VERSION_PATCH -ne 0 ]]; then
STATUS=1
fi
else
STATUS=1
fi
fi
else
2022-12-24 17:29:55 +01:00
if [[ $(($VERSION_MAJOR - 1)) -eq CURRENT_VERSION_MAJOR ]]; then
2022-12-21 13:18:38 +01:00
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
2022-12-24 17:29:55 +01:00
echo "- :no_entry_sign: Version skipped steps from the previous version $CURRENT_VERSION and thus does not follow the semantic versioning schema." >> $GITHUB_STEP_SUMMARY
echo "- :warning: Please see https://semver.org/ for further information." >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
exit 1
2022-12-24 17:29:55 +01:00
else
echo "- is an increment from the previous version :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
fi
2022-12-24 17:29:55 +01:00
## =================================
## provide variables for subsequent jobs
## ---------------------------------
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "new=$VERSION" >> $GITHUB_OUTPUT
2022-12-24 17:29:55 +01:00
create_package:
name: "create package"
needs: [version]
runs-on: ubuntu-latest
steps:
- run: echo "Creating package and release note for '${{ needs.version.outputs.new }}':" >> $GITHUB_STEP_SUMMARY
# 1. checkout the repo
- name: "checkout"
uses: actions/checkout@v3
# 2. create release note
2022-12-21 13:18:38 +01:00
- name: "create release note"
run: |
2022-12-30 19:14:26 +01:00
NEW_VERSION=${{ needs.version.outputs.new }}
2022-12-24 17:29:55 +01:00
CURRENT_VERSION=${{ needs.version.outputs.current }}
2022-12-21 13:18:38 +01:00
STATUS=0
2022-12-24 17:29:55 +01:00
## =================================
## create release note
## ---------------------------------
TOP=$(grep -n "## \[Unreleased\]" CHANGELOG.md | cut -d: -f1)
2022-12-24 17:29:55 +01:00
BOTTOM=$(grep -n -m 1 "## Version \[$CURRENT_VERSION\]" CHANGELOG.md | cut -d: -f1)
2022-12-30 19:14:26 +01:00
awk "NR>$TOP&&NR<$BOTTOM" CHANGELOG.md > release-note-v$NEW_VERSION.md
sed -i -- "s/###/##/g" release-note-v$NEW_VERSION.md
2022-12-24 17:29:55 +01:00
## =================================
## check if release note is empty
## ---------------------------------
2022-12-30 19:14:26 +01:00
WORD_COUNT=$(wc -w release-note-v$NEW_VERSION.md | awk '{print $1}')
2022-12-21 13:18:38 +01:00
if [[ $WORD_COUNT -lt 4 ]]; then
STATUS=1
fi
if [ $STATUS = 1 ]; then
2022-12-24 17:29:55 +01:00
echo "- :no_entry_sign: 'Unreleased' section in CHANGELOG.md is empty" >> $GITHUB_STEP_SUMMARY
2022-12-30 19:14:26 +01:00
echo ":warning: Please provide a meaningful CHANGELOG.md for the new version $NEW_VERSION." >> $GITHUB_STEP_SUMMARY
2022-12-21 13:18:38 +01:00
exit 1
2022-12-24 17:29:55 +01:00
else
echo "- 'Unreleased' section in CHANGELOG.md has content :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-12-21 13:18:38 +01:00
fi
2022-12-24 17:29:55 +01:00
## =================================
## remove empty lines from top and bottom
## ---------------------------------
2022-12-30 19:14:26 +01:00
sed -i -e '/./,$!d' -e :a -e '/^\n*$/{$d;N;ba' -e '}' release-note-v$NEW_VERSION.md
2022-06-05 21:49:42 +02:00
2022-12-24 17:29:55 +01:00
# 3. 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
2022-12-24 17:29:55 +01:00
dest: TrainRuns.jl-v${{ needs.version.outputs.new }}.zip
- run: echo "- creating ZIP-Archive for the new release :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
2022-12-24 17:29:55 +01:00
# 4. upload artifact to share it with other jobs
2022-06-05 21:49:42 +02:00
- uses: actions/upload-artifact@v3
with:
path: |
2022-12-24 17:29:55 +01:00
release-note-v${{ needs.version.outputs.new }}.md
TrainRuns.jl-v${{ needs.version.outputs.new }}.zip
2022-06-05 21:49:42 +02:00
if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn`
2022-12-24 17:29:55 +01:00
- run: echo "- providing ZIP-Archive and release notes for other jobs :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
publish_github:
2022-12-24 17:29:55 +01:00
needs: [create_package, version]
2022-06-05 21:49:42 +02:00
name: "publish on github"
runs-on: ubuntu-latest
steps:
2022-12-24 17:29:55 +01:00
- run: echo "Publishing package on Github:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
# 1. download artifact in folder artifact/
- uses: actions/download-artifact@v3
2022-12-24 17:29:55 +01:00
- run: echo "- getting ZIP-Archive and release notes :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
# 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 }}
2022-12-24 17:29:55 +01:00
body_path: artifact/release-note-v${{ needs.version.outputs.new }}.md
2022-06-05 21:49:42 +02:00
draft: false
prerelease: false
2022-12-24 17:29:55 +01:00
- run: echo "- drafting new release :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
# 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 }}
2022-12-24 17:29:55 +01:00
asset_path: artifact/TrainRuns.jl-v${{ needs.version.outputs.new }}.zip
asset_name: TrainRuns.jl-v${{ needs.version.outputs.new }}.zip
2022-06-05 21:49:42 +02:00
asset_content_type: application/zip
2022-12-24 17:29:55 +01:00
- run: echo "- upload release asset :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
# 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 }}
2022-12-24 17:29:55 +01:00
- run: echo "- publish release at ${{ steps.create_release.outputs.html_url }} :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
2022-12-24 17:29:55 +01:00
zenodo:
needs: [create_package, version]
2022-06-05 21:49:42 +02:00
name: "publish on zenodo"
outputs:
doi: ${{ steps.zenodraft.outputs.doi }}
runs-on: ubuntu-latest
steps:
2022-12-24 17:29:55 +01:00
- run: echo "Archiving package on zenodo to get a DOI:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
# 1. download artifact in folder artifact/ and move it one level up
- uses: actions/download-artifact@v3
- run: |
2022-12-24 17:29:55 +01:00
mv ./artifact/TrainRuns.jl-v${{ needs.version.outputs.new }}.zip ./
echo "- getting ZIP-Archive and release notes :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
# 2. install zenodraft
- name: "install zenodraft"
2022-12-24 17:29:55 +01:00
env:
URL: "https://zenodo.org/"
run: |
STATUS=0
npm install -g zenodraft
echo "- installing zenodraft :white_check_mark:" >> $GITHUB_STEP_SUMMARY
if ! curl --output /dev/null --silent --head --fail "$URL"; then
STATUS=1
fi
if [ $STATUS = 1 ]; then
echo "- :no_entry_sign: $URL is not reachable" >> $GITHUB_STEP_SUMMARY
echo ":warning: Please re-run action later!" >> $GITHUB_STEP_SUMMARY
echo ":warning: Please remove github release manually!" >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "- $URL is reachable :white_check_mark:" >> $GITHUB_STEP_SUMMARY
fi
# 3. Update zenodo metadata.json
- name: "Update zenodo metadata.json"
run: |
VERSION=${{ needs.version.outputs.new }}
sed -i".backup" -e"s/\"version\": \"%%\[SCRIPT\]\"/\"version\": \"$VERSION\"/g" .github/zenodo/metadata.json
echo "- updating zenodo metadata :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
2022-12-24 17:29:55 +01:00
# 4. upload new release to zenodo
2022-06-05 21:49:42 +02:00
- name: "uploading to zenodo"
id: zenodraft
env:
ZENODO_ACCESS_TOKEN: ${{ secrets.ZENODO_ACCESS_TOKEN }}
COLLECTION: 6448563
run: |
2022-12-24 17:29:55 +01:00
DOI=$(zenodraft deposition create version $COLLECTION)
zenodraft file add $DOI TrainRuns.jl-v*.zip
zenodraft metadata update $DOI .github/zenodo/metadata.json
zenodraft deposition publish $DOI
## =================================
## provide variables for subsequent jobs
## ---------------------------------
echo "doi=$DOI" >> $GITHUB_OUTPUT
echo "- publish release at zenodo with DOI: $DOI :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
2022-12-24 17:29:55 +01:00
update_repository:
needs: [zenodo, version]
name: "updating CITATION.cff and CHANGELOG.md"
2022-06-05 21:49:42 +02:00
runs-on: ubuntu-latest
steps:
2022-12-24 17:29:55 +01:00
- run: echo "Updating CITATION.cff and CHANGELOG.md:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
# 1. checkout the repo
- name: "checkout"
uses: actions/checkout@v3
2022-12-24 17:29:55 +01:00
# with:
# ref: main
# 2. update CITATION.cff
- name: "update CITATION.cff"
run: |
2022-06-05 21:49:42 +02:00
DATE=$(date "+%Y-%m-%d")
2022-12-24 17:29:55 +01:00
VERSION=${{ needs.version.outputs.new }}
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
2022-12-24 17:29:55 +01:00
echo "- updated CITATION.cff :white_check_mark:" >> $GITHUB_STEP_SUMMARY
# 3. update CHANGELOG.md
- name: "update CHANGELOG.md"
run: |
DATE=$(date "+%Y-%m-%d")
2022-12-24 17:29:55 +01:00
VERSION=${{ needs.version.outputs.new }}
URL="https://github.com/railtoolkit/TrainRuns.jl/compare"
2022-12-24 17:29:55 +01:00
CURRENT_VERSION=${{ needs.version.outputs.current }}
2022-12-21 13:18:38 +01:00
echo "increment CHANGELOG.md"
sed -i -- "/## \[Unreleased\]/a\\\n\n## Version [$VERSION] $DATE" CHANGELOG.md
2022-12-24 17:29:55 +01:00
sed -i -- "s|^\[Unreleased\]: .*$|\[Unreleased\]: $URL/v$VERSION...main\n\[$VERSION\]: $URL/v$CURRENT_VERSION...v$VERSION|" CHANGELOG.md
echo "- updated CHANGELOG.md :white_check_mark:" >> $GITHUB_STEP_SUMMARY
# 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:
2022-12-24 17:29:55 +01:00
message: "updated to ${{ needs.version.outputs.new }} (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-12-24 17:29:55 +01:00
- run: echo "- updated repository with new CITATION.cff and CHANGELOG.md :white_check_mark:" >> $GITHUB_STEP_SUMMARY
2022-06-05 21:49:42 +02:00
2022-12-24 17:29:55 +01:00
register_julia:
needs: [update_repository]
2022-12-30 19:02:57 +01:00
name: "register 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:
2022-12-24 17:29:55 +01:00
needs: [zenodo, version, create_package]
2022-12-30 19:02:57 +01:00
name: "Send toot about it to 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:
2022-12-24 17:29:55 +01:00
message: "The new version ${{ needs.version.outputs.new }} of TrainRuns.jl is available! DOI: https://doi.org/${{ needs.publish_zenodo.outputs.doi }} Further information at at ${{ needs.create_release.outputs.html_url }}."
2022-12-19 22:02:19 +01:00
visibility: "public" # default: public
env:
MASTODON_URL: "https://fosstodon.org/"
MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }} # access token