|
| 1 | +name: Create Release |
| 2 | +# example: gh workflow run release.yml -f tag_name=v1.1.4 -f draft=true |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag_name: |
| 7 | + default: "" |
| 8 | + draft: |
| 9 | + default: false |
| 10 | + prerelease: |
| 11 | + default: false |
| 12 | + |
| 13 | +jobs: |
| 14 | + prepare-release: |
| 15 | + name: Prepare release |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Check naming convention |
| 20 | + run: | |
| 21 | + VERIF=$(echo ${{ github.event.inputs.tag_name }} | grep -E "^v([0-9]{1,}\.)([0-9]{1,}\.)([0-9]{1,})(-(alpha|beta)\.[0-9]{1,})?$") |
| 22 | + if [ ! ${VERIF} ] |
| 23 | + then |
| 24 | + echo "Tag name '${{ github.event.inputs.tag_name }}' does not comply with naming convention vX.Y.Z" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | +
|
| 28 | + - name: Set version number without v |
| 29 | + run: | |
| 30 | + echo "VERSION_NUMBER=$(echo ${{ github.event.inputs.tag_name }} | sed 's/v//g' )" >> $GITHUB_ENV |
| 31 | +
|
| 32 | + - name: Clone sources |
| 33 | + uses: actions/checkout@v2 |
| 34 | + |
| 35 | + - name: Check version ${{ env.VERSION_NUMBER }} consistency in files |
| 36 | + # Check src/Constants.php and CHANGELOG.md |
| 37 | + run: | |
| 38 | + CURRENT_DATE=$(date +'%Y-%m-%d') |
| 39 | + echo $CURRENT_DATE |
| 40 | + CHANGELOG_VERSION=$(grep -o -E "## \[(.*)\] - $CURRENT_DATE" CHANGELOG.md | head -1 | sed 's/ //g') |
| 41 | + echo $CHANGELOG_VERSION |
| 42 | + if [[ $CHANGELOG_VERSION == "##[${{ env.VERSION_NUMBER }}]-$CURRENT_DATE" ]] |
| 43 | + then |
| 44 | + echo "CHANGELOG VERSION OK" |
| 45 | + else |
| 46 | + echo "CHANGELOG VERSION KO" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + CONSTANT_VERSION=$(grep -E "public const VERSION = 'v(.*)';" src/Constants.php | sed 's/ //g') |
| 50 | + if [[ $CONSTANT_VERSION == "publicconstVERSION='v${{ env.VERSION_NUMBER }}';" ]] |
| 51 | + then |
| 52 | + echo "CONSTANT VERSION OK" |
| 53 | + else |
| 54 | + echo "CONSTANT VERSION KO" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | +
|
| 58 | + - name: Create Tag ${{ github.event.inputs.tag_name }} |
| 59 | + uses: actions/github-script@v3 |
| 60 | + with: |
| 61 | + github-token: ${{ github.token }} |
| 62 | + script: | |
| 63 | + github.git.createRef({ |
| 64 | + owner: context.repo.owner, |
| 65 | + repo: context.repo.repo, |
| 66 | + ref: "refs/tags/${{ github.event.inputs.tag_name }}", |
| 67 | + sha: context.sha |
| 68 | + }) |
| 69 | +
|
| 70 | + - name: Prepare release notes |
| 71 | + run: | |
| 72 | + VERSION_RELEASE_NOTES=$(awk -v ver="[${{ env.VERSION_NUMBER }}]" '/^## / { if (p) { exit }; if ($2 == ver) { p=1; next} } p && NF' CHANGELOG.md) |
| 73 | + echo "$VERSION_RELEASE_NOTES" >> CHANGELOG.txt |
| 74 | +
|
| 75 | +
|
| 76 | + - name: Create release ${{ env.VERSION_NUMBER }} |
| 77 | + uses: softprops/action-gh-release@v1 |
| 78 | + with: |
| 79 | + body_path: CHANGELOG.txt |
| 80 | + name: ${{ env.VERSION_NUMBER }} |
| 81 | + tag_name: ${{ github.event.inputs.tag_name }} |
| 82 | + draft: ${{ github.event.inputs.draft }} |
| 83 | + prerelease: ${{ github.event.inputs.prerelease }} |
0 commit comments