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@v4 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@v4 52 53 - name: Prepare Environment 54 run: | 55 php .github/release.php current >> $GITHUB_ENV 56 57 - name: Build Archives 58 run: | 59 git ls-files | while read path; do 60 if git check-attr export-ignore -- "$path" | grep -q 'export-ignore: set'; then 61 echo "Deleting $path" 62 rm -f "$path" 63 fi 64 done 65 find . -type d -empty -delete 66 mkdir -p data/pages/playground 67 echo "====== PlayGround ======" > data/pages/playground/playground.txt 68 cd .. 69 mv ${{ github.event.repository.name }} "dokuwiki-${{ env.current_file }}" 70 tar -czvf "dokuwiki-${{ env.current_file }}.tgz" dokuwiki-${{ env.current_file }} 71 zip -r "dokuwiki-${{ env.current_file }}.zip" dokuwiki-${{ env.current_file }} 72 rm -rf "dokuwiki-${{ env.current_file }}" 73 mkdir ${{ github.event.repository.name }} 74 mv "dokuwiki-${{ env.current_version }}.tgz" ${{ github.event.repository.name }}/ 75 mv "dokuwiki-${{ env.current_version }}.zip" ${{ github.event.repository.name }}/ 76 77 - name: Release to Github 78 id: release 79 uses: softprops/action-gh-release@v1 80 with: 81 name: DokuWiki ${{ env.current_raw }} [${{ env.current_update }}] 82 tag_name: release-${{ env.current_version }} 83 files: | 84 dokuwiki-${{ env.current_file }}.tgz 85 dokuwiki-${{ env.current_file }}.zip 86 outputs: 87 version: ${{ env.current_version }} 88 file: ${{ env.current_file }} 89 url: ${{ fromJSON(steps.release.outputs.assets)[0].browser_download_url }} 90 91 deploy: 92 name: Deploy Release 93 needs: build 94 runs-on: ubuntu-latest 95 steps: 96 - name: Download 97 run: | 98 wget ${{ needs.build.outputs.url }} -O dokuwiki-${{ needs.build.outputs.file }}.tgz 99 100 - name: Setup SSH Key 101 uses: shimataro/ssh-key-action@v2 102 with: 103 key: ${{ secrets.SSH_PRIVATE_KEY }} 104 # generate with ssh-keyscan -H <server> 105 known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }} 106 107 - name: Deploy to Server 108 run: | 109 scp "dokuwiki-${{ needs.build.outputs.file }}.tgz" ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:htdocs/src/dokuwiki/ 110 ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd htdocs/src/dokuwiki/ && tar -xzvf dokuwiki-${{ needs.build.outputs.file }}.tgz" 111