From ed992dfa5b85142998206b93c456fa009c46dfc1 Mon Sep 17 00:00:00 2001 From: modos189 Date: Mon, 1 Aug 2022 19:19:25 +0300 Subject: [PATCH 1/2] test --- .github/workflows/build.yml | 34 +++++++------- .github/workflows/build_pr.yml | 5 ++- .github/workflows/merge_pr.yml | 32 +++---------- ...pload_pr.yml => send_build_to_website.yml} | 45 +++++++++---------- 4 files changed, 47 insertions(+), 69 deletions(-) rename .github/workflows/{upload_pr.yml => send_build_to_website.yml} (70%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4c2d844c0..574bab8f7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,28 +55,12 @@ jobs: run: | echo "BUILDSTAMP=$(date -u +'%Y-%m-%d_%H-%M' -d"$(stat -c %y ./build/${{ env.BUILD_TYPE }}/total-conversion-build.user.js)")" >> "$GITHUB_ENV" - - name: Push build artifacts to website - env: - WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} - API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} - if: ${{ env.WEBSITE_REPO != '' }} - uses: dmnemec/copy_file_to_another_repo_action@main - with: - source_file: "./build/${{ env.BUILD_TYPE }}/." - destination_repo: ${{ secrets.WEBSITE_REPO }} - destination_branch: master - destination_folder: 'static/build/${{ env.ARCHIVE_DIR }}/${{ env.BUILDSTAMP }}/' - user_email: 'example@email.com' - user_name: 'IITC Updates' - commit_message: '🤖 New IITC ${{ env.BUILD_TYPE }} build from https://github.com/${{ github.repository }}/commit/${{ github.sha }}' - - uses: ncipollo/release-action@v1 if: startsWith(github.ref, 'refs/tags/v') with: allowUpdates: true artifactErrorsFailBuild: true artifacts: "./build/${{ env.BUILD_TYPE }}/*.zip,./build/${{ env.BUILD_TYPE }}/*.apk" - generateReleaseNotes: true token: ${{ secrets.GITHUB_TOKEN }} - name: Send APK to Telegram @@ -88,3 +72,21 @@ jobs: TEXT="🤖 *New IITC Mobile ${{ env.BUILD_TYPE }} build: *[${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }})" APIPARAMS="-F parse_mode=MarkdownV2 -F disable_notification=true -F chat_id=${{ env.TG_CHAT_ID }} https://api.telegram.org/bot${{ env.TG_BOT_TOKEN }}/sendDocument" curl -s -F document=@"${{ env.ARTIFACT_IITC_MOBILE }}" -F caption="$TEXT" $APIPARAMS + + - name: Save PR metadata + run: | + mkdir artifact + mv ./build/${{ env.BUILD_TYPE }} ./artifact/build + mkdir -p ./artifact/.metadata + echo ${{ env.BUILD_TYPE }} > ./artifact/.metadata/build_type + echo ${{ github.sha }} > ./artifact/.metadata/commit + echo $( ls ./artifact/build/ | grep '.apk' ) > ./artifact/.metadata/apk_filename + echo $( ls ./artifact/build/ | grep '.zip' ) > ./artifact/.metadata/zip_filename + echo $(date -u +'%Y-%m-%d_%H-%M' -d"$(stat -c %y ./artifact/build/total-conversion-build.user.js)") > ./artifact/.metadata/buildstamp + + - uses: actions/upload-artifact@v2 + with: + name: build + path: | + ./artifact/.metadata/ + ./artifact/build/ diff --git a/.github/workflows/build_pr.yml b/.github/workflows/build_pr.yml index 9bafebad7..3f81879c1 100644 --- a/.github/workflows/build_pr.yml +++ b/.github/workflows/build_pr.yml @@ -16,7 +16,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: '8' + java-version: '11' cache: 'gradle' - uses: actions/setup-python@v4 @@ -39,7 +39,8 @@ jobs: run: | mv ./build/${{ env.BUILD_TYPE }} ./build/build mkdir -p ./build/.metadata - echo ${{ github.event.number }} > ./build/.metadata/number + echo "PR" > ./build/.metadata/build_type + echo ${{ github.event.number }} > ./build/.metadata/pr_number echo ${{ github.event.pull_request.head.sha }} > ./build/.metadata/commit echo $( ls ./build/build/ | grep '.apk' ) > ./build/.metadata/apk_filename echo $( ls ./build/build/ | grep '.zip' ) > ./build/.metadata/zip_filename diff --git a/.github/workflows/merge_pr.yml b/.github/workflows/merge_pr.yml index 0f0d19a44..926f719a0 100644 --- a/.github/workflows/merge_pr.yml +++ b/.github/workflows/merge_pr.yml @@ -7,36 +7,14 @@ on: jobs: if_merged: - if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: - - - uses: actions/checkout@v3 - env: - WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} - if: ${{ env.WEBSITE_REPO != '' }} - with: - repository: ${{ secrets.WEBSITE_REPO }} - ref: 'master' - token: ${{ secrets.API_TOKEN_GITHUB }} - - - name: Setup git config - env: - WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} - if: ${{ env.WEBSITE_REPO != '' }} - run: | - git config user.name "userz" - git config user.email "<>" - - - name: Delete old build artifacts + - name: Send build artifacts to website env: WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} if: ${{ env.WEBSITE_REPO != '' }} run: | - git rm -r static/build/artifact/PR${{ github.event.number }}/ - git commit -m "🤖 PR №${{ github.event.number }} merged, deleting old build artifacts" - - - run: git push origin master - env: - WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} - if: ${{ env.WEBSITE_REPO != '' }} + curl -X POST https://api.github.com/repos/${{ secrets.WEBSITE_REPO }}/dispatches \ + -H 'Accept: application/vnd.github.everest-preview+json' \ + -u ${{ secrets.API_TOKEN_GITHUB }} \ + --data '{"event_type": "delete_iitc_pr_build", "client_payload": { "repo": {"pr_number": "${{ github.event.number }}" }}' diff --git a/.github/workflows/upload_pr.yml b/.github/workflows/send_build_to_website.yml similarity index 70% rename from .github/workflows/upload_pr.yml rename to .github/workflows/send_build_to_website.yml index 3fdee3531..efa0680a5 100644 --- a/.github/workflows/upload_pr.yml +++ b/.github/workflows/send_build_to_website.yml @@ -1,19 +1,17 @@ -name: Upload PR +name: Send build to website # read-write repo token # access to secrets on: workflow_run: - workflows: ["Build PR"] + workflows: ["Build PR", "Build IITC and push artifacts"] types: - completed jobs: upload: runs-on: ubuntu-latest - if: > - ${{ github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'success' }} + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: 'Download artifact' uses: actions/github-script@v6 @@ -39,16 +37,20 @@ jobs: let fs = require('fs'); fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/build.zip`, Buffer.from(download.data)); + core.exportVariable('REPO_OWNER', context.repo.owner); + core.exportVariable('REPO_NAME', context.repo.repo); + core.exportVariable('ARTIFACT_ID', matchArtifact.id); + - name: 'Unzip artifact' env: WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} - if: ${{ env.WEBSITE_REPO != '' }} + if: ${{ env.WEBSITE_REPO != '' && github.event.workflow_run.event == 'pull_request' }} run: unzip build.zip - name: Set env env: WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} - if: ${{ env.WEBSITE_REPO != '' }} + if: ${{ env.WEBSITE_REPO != '' && github.event.workflow_run.event == 'pull_request' }} run: | echo "PR_NUMBER=$(cat ./.metadata/number)" >> "$GITHUB_ENV" echo "COMMIT_HASH=$(cat ./.metadata/commit)" >> "$GITHUB_ENV" @@ -56,25 +58,10 @@ jobs: echo "BUILD_ZIP_FILENAME=$(cat ./.metadata/zip_filename)" >> "$GITHUB_ENV" echo "BUILDSTAMP=$(cat ./.metadata/buildstamp)" >> "$GITHUB_ENV" - - name: Push build artifacts to website - env: - WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} - API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }} - if: ${{ env.WEBSITE_REPO != '' }} - uses: dmnemec/copy_file_to_another_repo_action@main - with: - source_file: "./build/." - destination_repo: ${{ secrets.WEBSITE_REPO }} - destination_branch: master - destination_folder: 'static/build/artifact/PR${{ env.PR_NUMBER }}/' - user_email: 'example@email.com' - user_name: 'IITC Updates' - commit_message: '🤖 New build PR №${{ env.PR_NUMBER }} from https://github.com/${{ github.repository }}/commit/${{ github.sha }}' - - - name: Comment with build url + - name: Comment with build url for PR env: WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} - if: ${{ env.WEBSITE_REPO != '' }} + if: ${{ env.WEBSITE_REPO != '' && github.event.workflow_run.event == 'pull_request' }} uses: marocchino/sticky-pull-request-comment@v2 with: header: pr_release @@ -87,3 +74,13 @@ jobs: | [`${{ env.BUILD_ZIP_FILENAME }}`](https://github.com/${{ secrets.WEBSITE_REPO }}/raw/master/static/build/artifact/PR${{ env.PR_NUMBER }}/${{ env.BUILD_ZIP_FILENAME }}) | ${{ env.COMMIT_HASH }} | [See build on website](https://iitc.app/build/artifact/PR${{ env.PR_NUMBER }}/) + + - name: Send build artifacts to website + env: + WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }} + if: ${{ env.WEBSITE_REPO != '' }} + run: | + curl -X POST https://api.github.com/repos/${{ secrets.WEBSITE_REPO }}/dispatches \ + -H 'Accept: application/vnd.github.everest-preview+json' \ + -u ${{ secrets.API_TOKEN_GITHUB }} \ + --data '{"event_type": "new_iitc_build", "client_payload": { "repo": {"owner": "${{ env.REPO_OWNER }}", "repo": "${{ env.REPO_NAME }}"}, "artifact_id": "${{ env.ARTIFACT_ID }}" }}' From ac3e65594f68ce35e18ca99ebc96f2ec88d64d97 Mon Sep 17 00:00:00 2001 From: Alexander Danilov Date: Sun, 7 Aug 2022 04:16:57 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e3b817fbc..504c00395 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ It is available for desktop browsers, such as Firefox and Chrome, and as a mobil **[Website](https://iitc.app/) | [Documentation](https://iitc-ce.rtfd.io/) | [Telegram channel](https://t.me/iitc_news)** + + ## Users Install IITC: https://iitc.app/