CombinedWorkflow #629
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CombinedWorkflow | |
| on: | |
| schedule: | |
| - cron: '0 */8 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| sync_release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout master | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| fetch-depth: 0 | |
| - name: Get latest upstream release (non-prerelease) | |
| id: upstream | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const owner = 'OpenListTeam'; | |
| const repo = 'OpenList'; | |
| try { | |
| const res = await github.rest.repos.getLatestRelease({ owner, repo }); | |
| core.setOutput('tag_name', res.data.tag_name || ''); | |
| core.setOutput('body', res.data.body || ''); | |
| core.setOutput('html_url', res.data.html_url || ''); | |
| } catch (err) { | |
| if (err.status === 404) { | |
| core.setOutput('not_found', 'true'); | |
| } else { | |
| throw err; | |
| } | |
| } | |
| - name: Abort if no upstream non-prerelease release found | |
| if: steps.upstream.outputs.not_found == 'true' | |
| run: | | |
| echo "No upstream non-prerelease release found in OpenListTeam/OpenList. Exiting." | |
| - name: Read and normalize versions | |
| id: prep | |
| run: | | |
| raw_tag="${{ steps.upstream.outputs.tag_name }}" | |
| echo "raw_tag=$raw_tag" | |
| version="${raw_tag#v}" | |
| version="${version#V}" | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| if [ -f "OpenList/qpkg.cfg" ]; then | |
| cur=$(grep -E '^QPKG_VER' OpenList/qpkg.cfg | sed -E 's/.*=[[:space:]]*"?([^"]+)"?.*/\1/' || true) | |
| echo "current=$cur" >> $GITHUB_OUTPUT | |
| else | |
| echo "current=" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Exit if already up-to-date | |
| if: steps.prep.outputs.version == steps.prep.outputs.current | |
| run: | | |
| echo "QPKG_VER already at ${{ steps.prep.outputs.version }} — nothing to do." | |
| - name: Update OpenList/qpkg.cfg on master, commit and push | |
| if: steps.prep.outputs.version != steps.prep.outputs.current | |
| env: | |
| NEW_VERSION: ${{ steps.prep.outputs.version }} | |
| run: | | |
| set -e | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| if [ -f "OpenList/qpkg.cfg" ]; then | |
| sed -E -i 's/^(QPKG_VER[[:space:]]*=[[:space:]]*).*/\1"'"$NEW_VERSION"'"/' OpenList/qpkg.cfg || true | |
| if ! grep -q '^QPKG_VER' OpenList/qpkg.cfg; then | |
| echo "QPKG_VER=\"$NEW_VERSION\"" >> OpenList/qpkg.cfg | |
| fi | |
| else | |
| mkdir -p OpenList | |
| echo "QPKG_VER=\"$NEW_VERSION\"" > OpenList/qpkg.cfg | |
| fi | |
| git add OpenList/qpkg.cfg | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit after editing OpenList/qpkg.cfg." | |
| else | |
| git commit -m "chore: bump QPKG_VER to ${NEW_VERSION} (sync OpenListTeam/OpenList)" | |
| git push origin HEAD:master | |
| fi | |
| - name: Create tag v${{ steps.prep.outputs.version }} if missing | |
| if: steps.prep.outputs.version != steps.prep.outputs.current | |
| env: | |
| NEW_VERSION: ${{ steps.prep.outputs.version }} | |
| run: | | |
| set -e | |
| tag="v${NEW_VERSION}" | |
| if git ls-remote --tags origin | grep -q "refs/tags/${tag}$"; then | |
| echo "Tag ${tag} already exists; skipping tag creation." | |
| else | |
| git tag -a "${tag}" -m "${tag} (sync from OpenListTeam/OpenList)" | |
| git push origin "refs/tags/${tag}" | |
| fi | |
| - name: Create or update GitHub release for v${{ steps.prep.outputs.version }} | |
| if: steps.prep.outputs.version != steps.prep.outputs.current | |
| uses: actions/github-script@v6 | |
| env: | |
| VERSION: ${{ steps.prep.outputs.version }} | |
| with: | |
| script: | | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const tag_name = `v${process.env.VERSION}`; | |
| const upstream_url = `${{ steps.upstream.outputs.html_url }}`; | |
| const upstream_body = `${{ steps.upstream.outputs.body }}`; | |
| const body = `Sync from OpenListTeam/OpenList release ${tag_name}\n\nUpstream: ${upstream_url}\n\n${upstream_body}`; | |
| try { | |
| const existing = await github.rest.repos.getReleaseByTag({ owner, repo, tag: tag_name }); | |
| core.info(`Release for ${tag_name} already exists (id ${existing.data.id}), updating it.`); | |
| await github.rest.repos.updateRelease({ | |
| owner, | |
| repo, | |
| release_id: existing.data.id, | |
| tag_name, | |
| name: tag_name, | |
| body, | |
| prerelease: false | |
| }); | |
| } catch (err) { | |
| if (err.status === 404) { | |
| core.info(`Creating release ${tag_name}`); | |
| await github.rest.repos.createRelease({ | |
| owner, | |
| repo, | |
| tag_name, | |
| name: tag_name, | |
| body, | |
| prerelease: false | |
| }); | |
| } else { | |
| throw err; | |
| } | |
| } | |
| - name: Install packages | |
| if: steps.prep.outputs.version != steps.prep.outputs.current | |
| run: | | |
| sudo apt-get update -y && \ | |
| sudo apt-get install -y --no-install-recommends \ | |
| git-core \ | |
| ca-certificates \ | |
| wget \ | |
| python-is-python3 \ | |
| make \ | |
| gcc | |
| # Runs a set of commands using the runners shell | |
| - name: Setup QDK | |
| if: steps.prep.outputs.version != steps.prep.outputs.current | |
| run: | | |
| git clone https://github.com/qnap-dev/QDK.git && \ | |
| cd QDK && sudo ./InstallToUbuntu.sh install | |
| # Runs a set of commands using the runners shell | |
| - name: Fetch OpenList | |
| if: steps.prep.outputs.version != steps.prep.outputs.current | |
| run: sh build/fetch.sh | |
| # Runs a set of commands using the runners shell | |
| - name: Build QNAP packages | |
| if: steps.prep.outputs.version != steps.prep.outputs.current | |
| run: sh build/build-qpkg.sh | |
| # Runs a set of commands using the runners shell | |
| - name: ls | |
| if: steps.prep.outputs.version != steps.prep.outputs.current | |
| run: ls -lrt | |
| # - uses: actions/upload-artifact@v3 | |
| # with: | |
| # name: my-artifact | |
| # path: | | |
| # *.qpkg | |
| # *.md5 | |
| - name: Release | |
| if: steps.prep.outputs.version != steps.prep.outputs.current | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ steps.prep.outputs.version }} | |
| files: | | |
| *.qpkg | |
| *.md5 |