From 8ab8c7ef40da3cdad533286269787089508ffebb Mon Sep 17 00:00:00 2001 From: Peter Njeim Date: Thu, 2 Jun 2022 21:00:10 -0300 Subject: [PATCH] Update and rename release.yaml to publish_new_release.yaml --- .github/workflows/publish_new_release.yaml | 72 +++++++++++++++++ .github/workflows/release.yaml | 89 ---------------------- 2 files changed, 72 insertions(+), 89 deletions(-) create mode 100644 .github/workflows/publish_new_release.yaml delete mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/publish_new_release.yaml b/.github/workflows/publish_new_release.yaml new file mode 100644 index 0000000..52feef1 --- /dev/null +++ b/.github/workflows/publish_new_release.yaml @@ -0,0 +1,72 @@ +name: Publish new release + +on: + schedule: + - cron: "0 0 * * 0" + workflow_dispatch: + inputs: + version: + description: "The version number. default: the version number in package.json" + required: false + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +env: + VERSION: ${{ github.event.inputs.version }} + NPM_TAG: latest + REF: ${{ github.sha }} + ARTIFACTS_DIR: ./.artifacts + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ env.REF }} + - name: Check for new release + run: | + echo "updated=false" >> $GITHUB_ENV + if [[ "$(npm show dl-librescore version)" != "$(node -p "require('./package.json').version")" ]]; then + echo "updated=true" >> $GITHUB_ENV + fi + - uses: actions/setup-node@v2.4.1 + if: env.updated + with: + node-version: 16 + registry-url: https://registry.npmjs.org/ + - name: Build userscript and command-line tool + if: env.updated + run: | + VER=$(node -p "require('./package.json').version") + echo "VERSION=$VER" >> $GITHUB_ENV + npm install + npm version --allow-same-version --no-git-tag $VERSION + npm run build + npm run pack:ext + - name: Publish command-line tool to NPM + if: env.updated + run: npm publish --tag $NPM_TAG + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Publish GitHub Release + if: env.updated + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + mkdir -p $ARTIFACTS_DIR + cp dist/main.user.js $ARTIFACTS_DIR/dl-librescore.user.js + wget -q https://github.com/LibreScore/dl-librescore/archive/$REF.tar.gz -O $ARTIFACTS_DIR/source.tar.gz + cd $ARTIFACTS_DIR + rm *.tar.gz + files=$(ls .) + assets=() + for f in $files; do [ -f "$f" ] && assets+=(-a "$f"); done + SHORT_SHA=$(echo $REF | cut -c 1-7) + hub release create "${assets[@]}" -m v$VERSION -t $REF v$VERSION + - name: Delete workflow run + if: ${{ !env.updated }} + run: | + curl -i -u ${{ secrets.LIBRESCORE_USERNAME }}:${{ secrets.LIBRESCORE_TOKEN }} -d '{"event_type":"delete_action","client_payload":{"run_id":"'"${{ github.run_id }}"'","repo":"LibreScore/dl-librescore"}}' -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/LibreScore/actions/dispatches diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 2b37b90..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,89 +0,0 @@ -name: Release - -on: - push: - tags: - - v* - workflow_dispatch: - inputs: - version: - description: "The version number. default: the version number in package.json" - required: false - npm_tag: - description: "The tag to register the published NPM package with" - required: false - default: "latest" - ref: - description: "The branch, tag or SHA to release from" - required: false - -env: - VERSION: ${{ github.event.inputs.version }} - NPM_TAG: ${{ github.event.inputs.npm_tag }} - REF: ${{ github.event.inputs.ref || github.sha }} - ARTIFACTS_DIR: ./.artifacts - -jobs: - release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2.3.5 - with: - ref: ${{ env.REF }} - - uses: actions/setup-node@v2.4.1 - with: - node-version: 16 - registry-url: https://registry.npmjs.org/ - - - name: Set Env - run: | - VER=$(node -p "require('./package.json').version") - echo "VERSION=$VER" >> $GITHUB_ENV - if: ${{ !env.VERSION }} - - - run: npm install - - name: Bump Version - run: npm version --allow-same-version --no-git-tag $VERSION - - run: npm run build - - run: npm run pack:ext - - - name: NPM Publish - run: npm publish --tag $NPM_TAG - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - - run: | - mkdir -p $ARTIFACTS_DIR - cp dist/main.user.js $ARTIFACTS_DIR/dl-librescore.user.js - wget -q https://github.com/LibreScore/dl-librescore/archive/$REF.tar.gz -O $ARTIFACTS_DIR/source.tar.gz - - - name: Github Release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - cd $ARTIFACTS_DIR - rm *.tar.gz - - files=$(ls .) - assets=() - for f in $files; do [ -f "$f" ] && assets+=(-a "$f"); done - - SHORT_SHA=$(echo $REF | cut -c 1-7) - - hub release create \ - "${assets[@]}" \ - -m v$VERSION \ - -t $REF \ - v$VERSION - - - name: Archive to archive.org - continue-on-error: true - env: - REPO: ${{ github.repository }} - run: | - URL="https://github.com/$REPO/releases/" - curl "https://web.archive.org/save/" \ - --compressed -s \ - -H 'Content-Type: application/x-www-form-urlencoded' \ - --data-raw "url=$URL&capture_all=on" \ - | grep github