summaryrefslogtreecommitdiffstats
path: root/.github/workflows/publish.yml
blob: 8a1bd9a0109c49c25919a460f1ea5135515ef2bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Publish
on:
  workflow_call:
    inputs:
      nightly:
        default: false
        required: false
        type: boolean
      version:
        required: true
        type: string
      target_commitish:
        required: true
        type: string
    secrets:
      ARCHIVE_REPO_TOKEN:
        required: false

permissions:
  contents: write

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0
      - uses: actions/download-artifact@v3
      - uses: actions/setup-python@v4
        with:
          python-version: "3.10"

      - name: Generate release notes
        run: |
          cat >> ./RELEASE_NOTES << EOF
          #### A description of the various files are in the [README](https://github.com/yt-dlp/yt-dlp#release-files)
          ---
          <details><summary><h3>Changelog</h3></summary>
          $(python ./devscripts/make_changelog.py -vv)
          </details>
          EOF
          echo "**This is an automated nightly pre-release build**" >> ./PRERELEASE_NOTES
          cat ./RELEASE_NOTES >> ./PRERELEASE_NOTES
          echo "Generated from: https://github.com/${{ github.repository }}/commit/${{ inputs.target_commitish }}" >> ./ARCHIVE_NOTES
          cat ./RELEASE_NOTES >> ./ARCHIVE_NOTES

      - name: Archive nightly release
        env:
          GH_TOKEN: ${{ secrets.ARCHIVE_REPO_TOKEN }}
          GH_REPO: ${{ vars.ARCHIVE_REPO }}
        if: |
          inputs.nightly && env.GH_TOKEN != '' && env.GH_REPO != ''
        run: |
          gh release create \
            --notes-file ARCHIVE_NOTES \
            --title "yt-dlp nightly ${{ inputs.version }}" \
            ${{ inputs.version }} \
            artifact/*

      - name: Prune old nightly release
        if: inputs.nightly && !vars.ARCHIVE_REPO
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          gh release delete --yes --cleanup-tag "nightly" || true
          git tag --delete "nightly" || true
          sleep 5  # Enough time to cover deletion race condition

      - name: Publish release${{ inputs.nightly && ' (nightly)' || '' }}
        env:
          GH_TOKEN: ${{ github.token }}
        if: (inputs.nightly && !vars.ARCHIVE_REPO) || !inputs.nightly
        run: |
          gh release create \
            --notes-file ${{ inputs.nightly && 'PRE' || '' }}RELEASE_NOTES \
            --target ${{ inputs.target_commitish }} \
            --title "yt-dlp ${{ inputs.nightly && 'nightly ' || '' }}${{ inputs.version }}" \
            ${{ inputs.nightly && '--prerelease "nightly"' || inputs.version }} \
            artifact/*