|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: ~ |
| 5 | + push: |
| 6 | + branches: [ master ] |
| 7 | + |
| 8 | +jobs: |
| 9 | + |
| 10 | + # Create a Release |
| 11 | + create_release: |
| 12 | + name: 🚀 Create Release |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + release_exists: ${{ steps.check_release.outputs.release_exists }} |
| 16 | + release_id: ${{ steps.check_release.outputs.release_id }} |
| 17 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 18 | + steps: |
| 19 | + - name: Get current date |
| 20 | + id: date |
| 21 | + run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT |
| 22 | + - name: Check if release exists |
| 23 | + id: check_release |
| 24 | + run: | |
| 25 | + release_name="${{ steps.date.outputs.date }}" |
| 26 | + release_data=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases/tags/${release_name}") |
| 27 | + if [ "$release_id" != "null" ]; then |
| 28 | + echo "release_exists=true" >> $GITHUB_OUTPUT |
| 29 | + echo "release_id=$(echo $release_data | jq -r '.id')" >> $GITHUB_OUTPUT |
| 30 | + else |
| 31 | + echo "release_exists=false" >> $GITHUB_OUTPUT |
| 32 | + fi |
| 33 | + - name: Delete Existing Release |
| 34 | + if: steps.check_release.outputs.release_exists == 'true' |
| 35 | + run: | |
| 36 | + curl -L \ |
| 37 | + -X DELETE \ |
| 38 | + -H "Accept: application/vnd.github+json" \ |
| 39 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 40 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 41 | + https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.check_release.outputs.release_id }} |
| 42 | + |
| 43 | + curl \ |
| 44 | + -X DELETE \ |
| 45 | + -H "Accept: application/vnd.github+json" \ |
| 46 | + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ |
| 47 | + https://api.github.com/repos/${{ github.repository }}/git/refs/tags/${{ steps.date.outputs.date }} |
| 48 | + - name: Create Release |
| 49 | + id: create_release |
| 50 | + uses: actions/create-release@v1 |
| 51 | + env: |
| 52 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + with: |
| 54 | + tag_name: ${{ steps.date.outputs.date }} |
| 55 | + release_name: Amendment ${{ steps.date.outputs.date }} |
| 56 | + draft: false |
| 57 | + prerelease: false |
| 58 | + |
| 59 | + upload_pdf: |
| 60 | + name: 🚀 Upload PDF Copy |
| 61 | + needs: create_release # Depends on release being created for upload URL |
| 62 | + runs-on: ubuntu-latest |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v3 |
| 65 | + - name: Install TexLive, TexLive formats-extra, Git, and Make |
| 66 | + run: | |
| 67 | + sudo apt-get update |
| 68 | + sudo apt-get install -y texlive texlive-formats-extra git make |
| 69 | + - name: 🔨 Build |
| 70 | + run: | |
| 71 | + make |
| 72 | + - name: 🌥️⬆️ Upload Assets - New Release |
| 73 | + uses: actions/upload-release-asset@v1 |
| 74 | + env: |
| 75 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + with: |
| 77 | + upload_url: ${{ needs.create_release.outputs.upload_url }} |
| 78 | + asset_name: Constitution.pdf |
| 79 | + asset_path: ./constitution.pdf |
| 80 | + asset_content_type: application/pdf |
| 81 | + |
0 commit comments