xref: /dokuwiki/.github/workflows/release-build.yml (revision 4d2a091249064944e0364103ebb1002794cb6480)
1290ea73dSAndreas Gohr# This workflow creates a new tag, builds the release archives and uploads them to GitHub and our server
2290ea73dSAndreas Gohr# It is triggered by pushing to the stable branch, either manually or by merging a PR created by the
3290ea73dSAndreas Gohr# release-preparation workflow
4290ea73dSAndreas Gohr
5290ea73dSAndreas Gohrname: "Release: Tag, Build & Deploy"
6290ea73dSAndreas Gohron:
7290ea73dSAndreas Gohr  push:
8290ea73dSAndreas Gohr    branches:
9290ea73dSAndreas Gohr      - stable
10290ea73dSAndreas Gohr
11290ea73dSAndreas Gohrjobs:
12290ea73dSAndreas Gohr
13290ea73dSAndreas Gohr  tag:
14290ea73dSAndreas Gohr    name: Tag Release
15290ea73dSAndreas Gohr    runs-on: ubuntu-latest
16290ea73dSAndreas Gohr    steps:
17290ea73dSAndreas Gohr      - name: Checkout
18*4d2a0912SAndreas Gohr        uses: actions/checkout@v4
19290ea73dSAndreas Gohr
20290ea73dSAndreas Gohr      - name: Prepare Environment
21290ea73dSAndreas Gohr        run: |
22290ea73dSAndreas Gohr          php .github/release.php current >> $GITHUB_ENV
23290ea73dSAndreas Gohr
24290ea73dSAndreas Gohr      - name: Check if a tag already exists
25290ea73dSAndreas Gohr        run: |
26290ea73dSAndreas Gohr          if git rev-parse "release-${{ env.current_version }}" >/dev/null 2>&1; then
27290ea73dSAndreas Gohr            echo "::error::Tag already exists, be sure to update the VERSION file for a hotfix"
28290ea73dSAndreas Gohr            exit 1
29290ea73dSAndreas Gohr          fi
30290ea73dSAndreas Gohr
31290ea73dSAndreas Gohr      - name: Create tag
32290ea73dSAndreas Gohr        uses: actions/github-script@v6
33290ea73dSAndreas Gohr        with:
34290ea73dSAndreas Gohr          # a privileged token is needed here to create the (protected) tag
35290ea73dSAndreas Gohr          github-token: ${{ secrets.RELEASE_TOKEN }}
36290ea73dSAndreas Gohr          script: |
37290ea73dSAndreas Gohr            const {current_version} = process.env;
38290ea73dSAndreas Gohr            github.rest.git.createRef({
39290ea73dSAndreas Gohr                owner: context.repo.owner,
40290ea73dSAndreas Gohr                repo: context.repo.repo,
41290ea73dSAndreas Gohr                ref: `refs/tags/release-${current_version}`,
42290ea73dSAndreas Gohr                sha: context.sha
43290ea73dSAndreas Gohr            });
44290ea73dSAndreas Gohr
45290ea73dSAndreas Gohr  build:
46290ea73dSAndreas Gohr    name: Build Release
47290ea73dSAndreas Gohr    needs: tag
48290ea73dSAndreas Gohr    runs-on: ubuntu-latest
49290ea73dSAndreas Gohr    steps:
50290ea73dSAndreas Gohr      - name: Checkout
51*4d2a0912SAndreas Gohr        uses: actions/checkout@v4
52290ea73dSAndreas Gohr
53290ea73dSAndreas Gohr      - name: Prepare Environment
54290ea73dSAndreas Gohr        run: |
55290ea73dSAndreas Gohr          php .github/release.php current >> $GITHUB_ENV
56290ea73dSAndreas Gohr
57290ea73dSAndreas Gohr      - name: Build Archives
58290ea73dSAndreas Gohr        run: |
59290ea73dSAndreas Gohr          for F in $(awk '/export-ignore/{print $1}' .gitattributes); do
60290ea73dSAndreas Gohr            rm -rf $F
61290ea73dSAndreas Gohr          done
62290ea73dSAndreas Gohr          mkdir -p data/pages/playground
63290ea73dSAndreas Gohr          echo "====== PlayGround ======" > data/pages/playground/playground.txt
64290ea73dSAndreas Gohr          cd ..
65290ea73dSAndreas Gohr          mv ${{ github.event.repository.name }} "dokuwiki-${{ env.current_file }}"
66290ea73dSAndreas Gohr          tar -czvf "dokuwiki-${{ env.current_file }}.tgz" dokuwiki-${{ env.current_file }}
67290ea73dSAndreas Gohr          zip -r "dokuwiki-${{ env.current_file }}.zip" dokuwiki-${{ env.current_file }}
68290ea73dSAndreas Gohr          rm -rf "dokuwiki-${{ env.current_file }}"
69290ea73dSAndreas Gohr          mkdir ${{ github.event.repository.name }}
70290ea73dSAndreas Gohr          mv "dokuwiki-${{ env.current_version }}.tgz" ${{ github.event.repository.name }}/
71290ea73dSAndreas Gohr          mv "dokuwiki-${{ env.current_version }}.zip" ${{ github.event.repository.name }}/
72290ea73dSAndreas Gohr
73290ea73dSAndreas Gohr      - name: Release to Github
74290ea73dSAndreas Gohr        id: release
75290ea73dSAndreas Gohr        uses: softprops/action-gh-release@v1
76290ea73dSAndreas Gohr        with:
77290ea73dSAndreas Gohr          name: DokuWiki ${{ env.current_raw }} [${{ env.current_update }}]
78290ea73dSAndreas Gohr          tag_name: release-${{ env.current_version }}
79290ea73dSAndreas Gohr          files: |
80290ea73dSAndreas Gohr            dokuwiki-${{ env.current_file }}.tgz
81290ea73dSAndreas Gohr            dokuwiki-${{ env.current_file }}.zip
82290ea73dSAndreas Gohr    outputs:
83290ea73dSAndreas Gohr      version: ${{ env.current_version }}
84290ea73dSAndreas Gohr      file: ${{ env.current_file }}
85fac3e3efSAndreas Gohr      url: ${{ fromJSON(steps.release.outputs.assets)[0].browser_download_url }}
86290ea73dSAndreas Gohr
87290ea73dSAndreas Gohr  deploy:
88290ea73dSAndreas Gohr    name: Deploy Release
89290ea73dSAndreas Gohr    needs: build
90290ea73dSAndreas Gohr    runs-on: ubuntu-latest
91290ea73dSAndreas Gohr    steps:
92290ea73dSAndreas Gohr      - name: Download
93290ea73dSAndreas Gohr        run: |
94fac3e3efSAndreas Gohr          wget ${{ needs.build.outputs.url }} -O dokuwiki-${{ needs.build.outputs.file }}.tgz
95290ea73dSAndreas Gohr
96290ea73dSAndreas Gohr      - name: Setup SSH Key
97290ea73dSAndreas Gohr        uses: shimataro/ssh-key-action@v2
98290ea73dSAndreas Gohr        with:
99290ea73dSAndreas Gohr          key: ${{ secrets.SSH_PRIVATE_KEY }}
100290ea73dSAndreas Gohr          # generate with ssh-keyscan -H <server>
101290ea73dSAndreas Gohr          known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
102290ea73dSAndreas Gohr
103290ea73dSAndreas Gohr      - name: Deploy to Server
104290ea73dSAndreas Gohr        run: |
105290ea73dSAndreas Gohr          scp "dokuwiki-${{ needs.build.outputs.file }}.tgz" ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:htdocs/src/dokuwiki/
106290ea73dSAndreas Gohr          ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd htdocs/src/dokuwiki/ && tar -xzvf dokuwiki-${{ needs.build.outputs.file }}.tgz"
107