1# This workflow creates a new tag, builds the release archives and uploads them to GitHub and our server 2# It is triggered by pushing to the stable branch, either manually or by merging a PR created by the 3# release-preparation workflow 4 5name: "Release: Tag, Build & Deploy" 6on: 7 push: 8 branches: 9 - stable 10 11jobs: 12 13 tag: 14 name: Tag Release 15 runs-on: ubuntu-latest 16 steps: 17 - name: Checkout 18 uses: actions/checkout@v3 19 20 - name: Prepare Environment 21 run: | 22 php .github/release.php current >> $GITHUB_ENV 23 24 - name: Check if a tag already exists 25 run: | 26 if git rev-parse "release-${{ env.current_version }}" >/dev/null 2>&1; then 27 echo "::error::Tag already exists, be sure to update the VERSION file for a hotfix" 28 exit 1 29 fi 30 31 - name: Create tag 32 uses: actions/github-script@v6 33 with: 34 # a privileged token is needed here to create the (protected) tag 35 github-token: ${{ secrets.RELEASE_TOKEN }} 36 script: | 37 const {current_version} = process.env; 38 github.rest.git.createRef({ 39 owner: context.repo.owner, 40 repo: context.repo.repo, 41 ref: `refs/tags/release-${current_version}`, 42 sha: context.sha 43 }); 44 45 build: 46 name: Build Release 47 needs: tag 48 runs-on: ubuntu-latest 49 steps: 50 - name: Checkout 51 uses: actions/checkout@v3 52 53 - name: Prepare Environment 54 run: | 55 php .github/release.php current >> $GITHUB_ENV 56 57 - name: Build Archives 58 run: | 59 for F in $(awk '/export-ignore/{print $1}' .gitattributes); do 60 rm -rf $F 61 done 62 mkdir -p data/pages/playground 63 echo "====== PlayGround ======" > data/pages/playground/playground.txt 64 cd .. 65 mv ${{ github.event.repository.name }} "dokuwiki-${{ env.current_file }}" 66 tar -czvf "dokuwiki-${{ env.current_file }}.tgz" dokuwiki-${{ env.current_file }} 67 zip -r "dokuwiki-${{ env.current_file }}.zip" dokuwiki-${{ env.current_file }} 68 rm -rf "dokuwiki-${{ env.current_file }}" 69 mkdir ${{ github.event.repository.name }} 70 mv "dokuwiki-${{ env.current_version }}.tgz" ${{ github.event.repository.name }}/ 71 mv "dokuwiki-${{ env.current_version }}.zip" ${{ github.event.repository.name }}/ 72 73 - name: Release to Github 74 id: release 75 uses: softprops/action-gh-release@v1 76 with: 77 name: DokuWiki ${{ env.current_raw }} [${{ env.current_update }}] 78 tag_name: release-${{ env.current_version }} 79 files: | 80 dokuwiki-${{ env.current_file }}.tgz 81 dokuwiki-${{ env.current_file }}.zip 82 outputs: 83 version: ${{ env.current_version }} 84 file: ${{ env.current_file }} 85 url: ${{ fromJSON(steps.release.outputs.assets)[0].browser_download_url }} 86 87 deploy: 88 name: Deploy Release 89 needs: build 90 runs-on: ubuntu-latest 91 steps: 92 - name: Download 93 run: | 94 wget ${{ needs.build.outputs.url }} -O dokuwiki-${{ needs.build.outputs.file }}.tgz 95 96 - name: Setup SSH Key 97 uses: shimataro/ssh-key-action@v2 98 with: 99 key: ${{ secrets.SSH_PRIVATE_KEY }} 100 # generate with ssh-keyscan -H <server> 101 known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }} 102 103 - name: Deploy to Server 104 run: | 105 scp "dokuwiki-${{ needs.build.outputs.file }}.tgz" ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:htdocs/src/dokuwiki/ 106 ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd htdocs/src/dokuwiki/ && tar -xzvf dokuwiki-${{ needs.build.outputs.file }}.tgz" 107