|
| 1 | +name: Create XPI and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' # Startet den Workflow bei neuen Versionstags |
| 9 | + workflow_dispatch: # Ermöglicht das manuelle Starten des Workflows |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + issues: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Check out the repository |
| 21 | + uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Extract name and version from manifest.json |
| 24 | + id: get_name_version |
| 25 | + run: | |
| 26 | + NAME=$(grep '"name"' src/manifest.json | sed -E 's/.*"name": "([^"]+)".*/\1/') |
| 27 | + VERSION=$(grep '"version"' src/manifest.json | sed -E 's/.*"version": "([^"]+)".*/\1/') |
| 28 | + echo "NAME=${NAME}" >> $GITHUB_ENV |
| 29 | + echo "VERSION=${VERSION}" >> $GITHUB_ENV |
| 30 | +
|
| 31 | + - name: Build XPI |
| 32 | + run: | |
| 33 | + mkdir -p build/PrioMailbox |
| 34 | + # Kopiere nur die notwendigen Dateien, um die XPI zu erstellen |
| 35 | + rsync -av --exclude="assets" --exclude=".*" --exclude="*.sh" ./src/ build/PrioMailbox/ |
| 36 | + # Manifest Datei anpassen |
| 37 | + sed -i 's/"name": "[^"]*"/"name": "PrioMailbox"/' build/PrioMailbox/manifest.json |
| 38 | + # XPI-Datei erstellen |
| 39 | + cd build/PrioMailbox |
| 40 | + zip -r ../${NAME}_v${VERSION}.xpi . -x ".*" "*.sh" "assets/*" |
| 41 | + cd ../.. |
| 42 | +
|
| 43 | + - name: Verify XPI File |
| 44 | + run: | |
| 45 | + if [ ! -f "./build/${NAME}_v${VERSION}.xpi" ]; then |
| 46 | + echo "XPI file not found!" |
| 47 | + exit 1 |
| 48 | + else |
| 49 | + echo "XPI file found at ./build/${NAME}_v${VERSION}.xpi" |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Check if release exists |
| 53 | + id: check_release |
| 54 | + uses: actions/github-script@v6 |
| 55 | + with: |
| 56 | + script: | |
| 57 | + const releases = await github.rest.repos.listReleases({ |
| 58 | + owner: context.repo.owner, |
| 59 | + repo: context.repo.repo, |
| 60 | + }); |
| 61 | + const release = releases.data.find(release => release.tag_name === `v${process.env.VERSION}`); |
| 62 | + if (release) { |
| 63 | + core.setOutput('release_id', release.id); |
| 64 | + core.setOutput('upload_url', release.upload_url); |
| 65 | + } else { |
| 66 | + core.setOutput('release_id', ''); |
| 67 | + core.setOutput('upload_url', ''); |
| 68 | + } |
| 69 | + env: |
| 70 | + VERSION: ${{ env.VERSION }} |
| 71 | + |
| 72 | + - name: Create Release |
| 73 | + if: ${{ steps.check_release.outputs.release_id == '' }} |
| 74 | + id: create_release |
| 75 | + uses: actions/create-release@v1 |
| 76 | + env: |
| 77 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 78 | + with: |
| 79 | + tag_name: v${{ env.VERSION }} |
| 80 | + release_name: "${{ env.NAME }} v${{ env.VERSION }}" |
| 81 | + draft: false |
| 82 | + prerelease: false |
| 83 | + |
| 84 | + - name: Upload XPI to Release |
| 85 | + if: ${{ steps.check_release.outputs.release_id == '' }} |
| 86 | + uses: actions/upload-release-asset@v1 |
| 87 | + env: |
| 88 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + with: |
| 90 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 91 | + asset_path: ./build/${{ env.NAME }}_v${{ env.VERSION }}.xpi |
| 92 | + asset_name: ${{ env.NAME }}_v${{ env.VERSION }}.xpi |
| 93 | + asset_content_type: application/x-xpinstall |
| 94 | + |
| 95 | + - name: Notify Release Exists |
| 96 | + if: ${{ steps.check_release.outputs.release_id != '' }} |
| 97 | + run: echo "Release v${{ env.VERSION }} already exists. Skipping asset upload." |
0 commit comments