|
| 1 | +# This is a basic workflow to help you get started with Actions |
| 2 | + |
| 3 | +name: CI |
| 4 | + |
| 5 | +# Controls when the action will run. Triggers the workflow on push or pull request |
| 6 | +# events but only for the master branch |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: [ main ] |
| 10 | + |
| 11 | +# A workflow run is made up of one or more jobs that can run sequentially or in parallel |
| 12 | +jobs: |
| 13 | + # This workflow contains a single job called "build" |
| 14 | + build: |
| 15 | + # The type of runner that the job will run on |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + # Steps represent a sequence of tasks that will be executed as part of the job |
| 19 | + steps: |
| 20 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 21 | + - uses: actions/checkout@v2 |
| 22 | + with: |
| 23 | + path: './crucible' |
| 24 | + |
| 25 | + - id: crucible |
| 26 | + uses: pozetroninc/[email protected] |
| 27 | + with: |
| 28 | + owner: cmu-sei |
| 29 | + repo: moodle-block_crucible |
| 30 | + excludes: prerelease, draft |
| 31 | + |
| 32 | + - name: package |
| 33 | + run: | |
| 34 | + OLDRELEASE=${{ steps.crucible.outputs.release }} |
| 35 | + PREVIOUSVERSION=$(grep "plugin->version" crucible/version.php | sed -e "s/.*= \(.*\);.*/\1/") |
| 36 | + if [ $OLDRELEASE -ne $PREVIOUSVERSION ]; then |
| 37 | + NEWVERSION=$PREVIOUSVERSION |
| 38 | + else |
| 39 | + OLDDATE=`echo $PREVIOUSVERSION | cut -b 1-8` |
| 40 | + NEWDATE=`date +%Y%m%d` |
| 41 | + if [ $OLDDATE -ne $NEWDATE ]; then |
| 42 | + NEWVERSION=$NEWDATE\00 |
| 43 | + else |
| 44 | + OLDVERS=`echo $PREVIOUSVERSION | cut -b 9-10` |
| 45 | + OLDVERS=${OLDVERS#0} |
| 46 | + let NEWVERS=(OLDVERS + 1) |
| 47 | + NEWVERSION=$OLDDATE`printf %02d $NEWVERS` |
| 48 | + fi |
| 49 | + sed -i "s#$PREVIOUSVERSION#$NEWVERSION#" crucible/version.php |
| 50 | + cd ./crucible |
| 51 | + git config user.name "github-actions[bot]" |
| 52 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 53 | + git add version.php |
| 54 | + git commit -m "Updating version to $NEWVERSION" |
| 55 | + git push |
| 56 | + cd .. |
| 57 | + fi |
| 58 | + zip -r block_crucible_$NEWVERSION.zip crucible/ -x "crucible/*.git*" |
| 59 | + echo "artifact_version=$NEWVERSION" >> $GITHUB_ENV |
| 60 | + echo "artifact_name=block_crucible_$NEWVERSION" >> $GITHUB_ENV |
| 61 | + - name: Create Release |
| 62 | + id: create_release |
| 63 | + uses: actions/create-release@v1 |
| 64 | + env: |
| 65 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 66 | + with: |
| 67 | + tag_name: ${{ env.artifact_version }} |
| 68 | + release_name: ${{ env.artifact_name }} |
| 69 | + draft: false |
| 70 | + prerelease: false |
| 71 | + |
| 72 | + - name: Upload Release Asset |
| 73 | + id: upload-release-asset |
| 74 | + uses: actions/upload-release-asset@v1 |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 77 | + with: |
| 78 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 79 | + asset_path: ./${{env.artifact_name}}.zip |
| 80 | + asset_name: ${{env.artifact_name}}.zip |
| 81 | + asset_content_type: application/zip |
0 commit comments