Skip to content

Send build to website #710

Send build to website

Send build to website #710

name: Send build to website
# read-write repo token
# access to secrets
on:
workflow_run:
workflows: ["Build PR", "Build IITC and push artifacts"]
types:
- completed
jobs:
upload:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 'Download artifact'
uses: actions/github-script@v7
env:
WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }}
if: ${{ env.WEBSITE_REPO != '' }}
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "build"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
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 != '' && github.event.workflow_run.event == 'pull_request' }}
run: unzip build.zip
- name: Set env
env:
WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }}
if: ${{ env.WEBSITE_REPO != '' && github.event.workflow_run.event == 'pull_request' }}
run: |
echo "PR_NUMBER=$(cat ./.metadata/pr_number)" >> "$GITHUB_ENV"
echo "COMMIT_HASH=$(cat ./.metadata/commit)" >> "$GITHUB_ENV"
echo "BUILD_APK_FILENAME=$(cat ./.metadata/apk_filename)" >> "$GITHUB_ENV"
echo "BUILD_ZIP_FILENAME=$(cat ./.metadata/zip_filename)" >> "$GITHUB_ENV"
echo "BUILDSTAMP=$(cat ./.metadata/buildstamp)" >> "$GITHUB_ENV"
- name: Comment with build url for PR
env:
WEBSITE_REPO: ${{ secrets.WEBSITE_REPO }}
if: ${{ env.WEBSITE_REPO != '' && github.event.workflow_run.event == 'pull_request' }}
uses: marocchino/sticky-pull-request-comment@v2
with:
header: pr_release
number: ${{ env.PR_NUMBER }}
message: |
## 🤖 Pull request artifacts
| file | commit |
| ---- | ------ |
| [`${{ env.BUILD_APK_FILENAME }}`](https://github.com/${{ secrets.WEBSITE_REPO }}/raw/master/static/build/artifact/PR${{ env.PR_NUMBER }}/${{ env.BUILD_APK_FILENAME }}) | ${{ env.COMMIT_HASH }} |
| [`${{ 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 != '' }}
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.API_TOKEN_GITHUB }}
repository: ${{ env.WEBSITE_REPO }}
event-type: 'new_iitc_build'
client-payload: '{ "repo": {"owner": "${{ env.REPO_OWNER }}", "repo": "${{ env.REPO_NAME }}"}, "artifact_id": "${{ env.ARTIFACT_ID }}" }'