|
| 1 | +name: Deploy and Create Release |
| 2 | +# example: gh workflow run release.yml -f tag_name=v1.1.4 |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag_name: |
| 7 | + default: "" |
| 8 | + deploy_to_wordpress: |
| 9 | + default: true |
| 10 | + |
| 11 | +jobs: |
| 12 | + deploy-create-release: |
| 13 | + name: Deploy and create release |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Check naming convention |
| 18 | + run: | |
| 19 | + VERIF=$(echo ${{ github.event.inputs.tag_name }} | grep -E "^v([0-9]{1,}\.)([0-9]{1,}\.)([0-9]{1,})(-(alpha|beta)\.[0-9]{1,})?$") |
| 20 | + if [ ! ${VERIF} ] |
| 21 | + then |
| 22 | + echo "Tag name '${{ github.event.inputs.tag_name }}' does not comply with naming convention vX.Y.Z" |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | +
|
| 26 | + - name: Set version number without v |
| 27 | + run: | |
| 28 | + echo "VERSION_NUMBER=$(echo ${{ github.event.inputs.tag_name }} | sed 's/v//g' )" >> $GITHUB_ENV |
| 29 | +
|
| 30 | + - name: Clone sources |
| 31 | + uses: actions/checkout@v2 |
| 32 | + |
| 33 | + - name: Check version ${{ env.VERSION_NUMBER }} consistency in files |
| 34 | + # Check crowdsec.php, readme.txt, inc/constants.php and CHANGELOG.md |
| 35 | + run: | |
| 36 | + CURRENT_DATE=$(date +'%Y-%m-%d') |
| 37 | + CHANGELOG_VERSION=$(grep -o -E "## \[(.*)\] - $CURRENT_DATE" CHANGELOG.md | head -1 | sed 's/ //g') |
| 38 | + echo $CURRENT_DATE |
| 39 | + echo $CHANGELOG_VERSION |
| 40 | + echo "##[${{ env.VERSION_NUMBER }}]-$CURRENT_DATE" |
| 41 | + if [[ $CHANGELOG_VERSION == "##[${{ env.VERSION_NUMBER }}]-$CURRENT_DATE" ]] |
| 42 | + then |
| 43 | + echo "Version in CHANGELOG.md: OK" |
| 44 | + else |
| 45 | + echo "Version in CHANGELOG.md: KO" |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + CROWDSEC_VERSION=$(grep -E "Version: (.*)" crowdsec.php | sed 's/ //g') |
| 49 | + echo $CROWDSEC_VERSION |
| 50 | + echo "*Version:${{ env.VERSION_NUMBER }}" |
| 51 | + if [[ $CROWDSEC_VERSION == "*Version:${{ env.VERSION_NUMBER }}" ]] |
| 52 | + then |
| 53 | + echo "Version in crowdsec.php: OK" |
| 54 | + else |
| 55 | + echo "Version in crowdsec.php: KO" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + CROWDSEC_STABLE=$(grep -E "Stable tag: (.*)" crowdsec.php | sed 's/ //g') |
| 59 | + echo $CROWDSEC_STABLE |
| 60 | + echo "*Stabletag:${{ env.VERSION_NUMBER }}" |
| 61 | + if [[ $CROWDSEC_STABLE == "*Stabletag:${{ env.VERSION_NUMBER }}" ]] |
| 62 | + then |
| 63 | + echo "Stable tag in crowdsec.php: OK" |
| 64 | + else |
| 65 | + echo "Stable tag in crowdsec.php: KO" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + README_STABLE=$(grep -E "Stable tag: (.*)" readme.txt | sed 's/ //g') |
| 69 | + echo $README_STABLE |
| 70 | + echo "Stabletag:${{ env.VERSION_NUMBER }}" |
| 71 | + if [[ $README_STABLE == "Stabletag:${{ env.VERSION_NUMBER }}" ]] |
| 72 | + then |
| 73 | + echo "Stable tag in readme.txt: OK" |
| 74 | + else |
| 75 | + echo "Stable tag in readme.txt: KO" |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | + CONSTANT_VERSION=$(grep -E "WordPress CrowdSec Bouncer/v(.*)" inc/constants.php | sed 's/[\x27(),/ ]//g') |
| 79 | + echo $CONSTANT_VERSION |
| 80 | + echo "defineCROWDSEC_BOUNCER_USER_AGENTWordPressCrowdSecBouncerv${{ env.VERSION_NUMBER }}" |
| 81 | + if [[ $CONSTANT_VERSION == "defineCROWDSEC_BOUNCER_USER_AGENTWordPressCrowdSecBouncerv${{ env.VERSION_NUMBER }};" ]] |
| 82 | + then |
| 83 | + echo "Version in inc/constants.php: OK" |
| 84 | + else |
| 85 | + echo "Version in inc/constants.php: KO" |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | +
|
| 89 | + - name: Create Tag ${{ github.event.inputs.tag_name }} |
| 90 | + uses: actions/github-script@v3 |
| 91 | + with: |
| 92 | + github-token: ${{ github.token }} |
| 93 | + script: | |
| 94 | + github.git.createRef({ |
| 95 | + owner: context.repo.owner, |
| 96 | + repo: context.repo.repo, |
| 97 | + ref: "refs/tags/${{ github.event.inputs.tag_name }}", |
| 98 | + sha: context.sha |
| 99 | + }) |
| 100 | +
|
| 101 | + - name: WordPress Plugin Deploy |
| 102 | + if: github.event.inputs.deploy_to_wordpress |
| 103 | + id: deploy |
| 104 | + uses: 10up/action-wordpress-plugin-deploy@2.0.0 |
| 105 | + with: |
| 106 | + generate-zip: true |
| 107 | + env: |
| 108 | + SVN_USERNAME: ${{ secrets.SVN_USERNAME }} |
| 109 | + SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} |
| 110 | + SLUG: crowdsec |
| 111 | + VERSION: ${{ env.VERSION_NUMBER }} |
| 112 | + |
| 113 | + - name: Prepare release notes |
| 114 | + run: | |
| 115 | + VERSION_RELEASE_NOTES=$(awk -v ver="[${{ env.VERSION_NUMBER }}]" '/^## / { if (p) { exit }; if ($2 == ver) { p=1; next} } p && NF' CHANGELOG.md) |
| 116 | + echo "$VERSION_RELEASE_NOTES" >> CHANGELOG.txt |
| 117 | + cat CHANGELOG.txt |
| 118 | +
|
| 119 | +
|
| 120 | + - name: Create release ${{ env.VERSION_NUMBER }} with Wordpress zip |
| 121 | + if: github.event.inputs.deploy_to_wordpress |
| 122 | + uses: softprops/action-gh-release@v1 |
| 123 | + with: |
| 124 | + files: crowdsec.zip |
| 125 | + body_path: CHANGELOG.txt |
| 126 | + name: ${{ env.VERSION_NUMBER }} |
| 127 | + tag_name: ${{ github.event.inputs.tag_name }} |
| 128 | + draft: false |
| 129 | + prerelease: false |
| 130 | + |
| 131 | + - name: Create release ${{ env.VERSION_NUMBER }} without Wordpress zip |
| 132 | + if: !github.event.inputs.deploy_to_wordpress |
| 133 | + uses: softprops/action-gh-release@v1 |
| 134 | + with: |
| 135 | + body_path: CHANGELOG.txt |
| 136 | + name: ${{ env.VERSION_NUMBER }} |
| 137 | + tag_name: ${{ github.event.inputs.tag_name }} |
| 138 | + draft: false |
| 139 | + prerelease: false |
0 commit comments