From 86f1b14e4a7e36090630eabefd2eebf5104040d6 Mon Sep 17 00:00:00 2001 From: sumire88 <151038614+sumire88@users.noreply.github.com> Date: Sun, 25 Aug 2024 07:55:41 -0400 Subject: [PATCH 1/9] ci/refactor(sync-upstream): rework workflow --- .github/workflows/sync-upstream.yaml | 68 +++++++++++++++++++++------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/.github/workflows/sync-upstream.yaml b/.github/workflows/sync-upstream.yaml index b7fe4f7..77d6a43 100644 --- a/.github/workflows/sync-upstream.yaml +++ b/.github/workflows/sync-upstream.yaml @@ -2,34 +2,70 @@ name: Synchronize upstream on: workflow_dispatch: + inputs: + project: + type: string + description: flake input to be synced + options: + - dae + - daed + required: true jobs: sync-upstream: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Generate GitHub auth token + # https://github.com/tibdex/github-app-token + id: generate_token + uses: tibdex/github-app-token@v2.1.0 with: - ref: main + app_id: ${{ secrets.GH_APP_ID }} + private_key: ${{ secrets.GH_APP_PRIVATE_KEY }} + + - uses: actions/checkout@main + with: + token: ${{ steps.generate_token.outputs.token }} - uses: DeterminateSystems/nix-installer-action@main - uses: DeterminateSystems/magic-nix-cache-action@main - uses: DeterminateSystems/flake-checker-action@main - - name: Check if sync-upstream branch exists in remote - id: check_remote_branch + - name: Get the latest upstream commit + id: upstream_commit + shell: bash run: | - echo "stdout=$(git ls-remote --heads origin unstable)" >> $GITHUB_OUTPUT + #!/usr/bin/env bash + set -euo pipefail + out=$(nix run nixpkgs#nix-prefetch-git -- --url 'git@github.com:${{ github.repository_owner }}/${{ inputs.project }}.git' --rev 'refs/heads/main' --fetch-submodules --quiet | jq -r '.rev' | cut -c1-7) + echo json_output=$out >> "$GITHUB_OUTPUT" + echo sha_short=$(echo $out | jq -r '.rev' | cut -c1-7) >> "$GITHUB_OUTPUT" - - name: update dae package + - name: update metadata for a project based off the latest upstream git commit + id: update_metadata + shell: bash run: | - git config user.name "daebot" - git config user.email "daebot@v2raya.org" - git checkout -B unstable + #!/usr/bin/env bash + set -euo pipefail + # Fetch the metadata for the project + json_output="${{ steps.upstream_commit.outputs.json_output }}" + # Extract the necessary values from the json_output + version=$(echo "$json_output" | jq -r '.version') + date=$(echo "$json_output" | jq -r '.date' | awk -F'T' '{print $1}') + rev=$(echo "$json_output" | jq -r '.rev') + rev_short=$(echo "$json_output" | jq -r '.rev' | cut -c1-7) + hash=$(echo "$json_output" | jq -r '.hash') + # Update the metadata.json file + jq --arg version "unstable-$date.$rev_short" \ + --arg rev "$rev" \ + --arg hash "$hash" \ + '.version = $version | .rev = $rev | .hash = $hash' \ + ./{{ inputs.project }}/metadata.json | tee ./{{ inputs.project }}/metadata.json.tmp + # Replace the original file + mv ./{{ inputs.project }}/{metadata.json.tmp,metadata.json} - nix run nixpkgs#nix-update -- --commit --version=branch --flake dae - - if [[ "${{ steps.check_remote_branch.outputs.stdout }}" != '' ]]; then - git pull origin unstable --rebase - fi - git push -u origin unstable - shell: bash + - uses: EndBug/add-and-commit@main + with: + add: "${{ inputs.project }}/metadata.json" + commit: --signoff + message: "chore(${{ inputs.project }}): pin ref to refs/head/main (${{ steps.upstream_commit.outputs.sha_short }})" From 0c01b54ced584d6af4ed26d3a3c56ca6085f7ba5 Mon Sep 17 00:00:00 2001 From: sumire88 <151038614+sumire88@users.noreply.github.com> Date: Sun, 25 Aug 2024 08:09:13 -0400 Subject: [PATCH 2/9] fix: apply minor fix --- .github/workflows/sync-upstream.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sync-upstream.yaml b/.github/workflows/sync-upstream.yaml index 77d6a43..da707cf 100644 --- a/.github/workflows/sync-upstream.yaml +++ b/.github/workflows/sync-upstream.yaml @@ -5,7 +5,7 @@ on: inputs: project: type: string - description: flake input to be synced + description: upstream project name options: - dae - daed @@ -41,7 +41,7 @@ jobs: echo json_output=$out >> "$GITHUB_OUTPUT" echo sha_short=$(echo $out | jq -r '.rev' | cut -c1-7) >> "$GITHUB_OUTPUT" - - name: update metadata for a project based off the latest upstream git commit + - name: Update metadata for a project based off the latest upstream git commit id: update_metadata shell: bash run: | From aa2b800335919f0879a17f994431df150e0e2204 Mon Sep 17 00:00:00 2001 From: sumire88 <151038614+sumire88@users.noreply.github.com> Date: Sun, 25 Aug 2024 08:37:42 -0400 Subject: [PATCH 3/9] patch(git-prefetch): use https url --- .github/workflows/sync-upstream.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-upstream.yaml b/.github/workflows/sync-upstream.yaml index da707cf..9af53d0 100644 --- a/.github/workflows/sync-upstream.yaml +++ b/.github/workflows/sync-upstream.yaml @@ -37,7 +37,7 @@ jobs: run: | #!/usr/bin/env bash set -euo pipefail - out=$(nix run nixpkgs#nix-prefetch-git -- --url 'git@github.com:${{ github.repository_owner }}/${{ inputs.project }}.git' --rev 'refs/heads/main' --fetch-submodules --quiet | jq -r '.rev' | cut -c1-7) + out=$(nix run nixpkgs#nix-prefetch-git -- --url 'https://github.com/${{ github.repository_owner }}/${{ inputs.project }}.git' --rev 'refs/heads/main' --fetch-submodules --quiet | jq -r '.rev' | cut -c1-7) echo json_output=$out >> "$GITHUB_OUTPUT" echo sha_short=$(echo $out | jq -r '.rev' | cut -c1-7) >> "$GITHUB_OUTPUT" From bca8f524d5f48bb64868b99745881fe1fd9a09b3 Mon Sep 17 00:00:00 2001 From: sumire88 <151038614+sumire88@users.noreply.github.com> Date: Sun, 25 Aug 2024 08:43:03 -0400 Subject: [PATCH 4/9] fix: fix syntax error --- .github/workflows/sync-upstream.yaml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/sync-upstream.yaml b/.github/workflows/sync-upstream.yaml index 9af53d0..5c0305b 100644 --- a/.github/workflows/sync-upstream.yaml +++ b/.github/workflows/sync-upstream.yaml @@ -36,9 +36,8 @@ jobs: shell: bash run: | #!/usr/bin/env bash - set -euo pipefail - out=$(nix run nixpkgs#nix-prefetch-git -- --url 'https://github.com/${{ github.repository_owner }}/${{ inputs.project }}.git' --rev 'refs/heads/main' --fetch-submodules --quiet | jq -r '.rev' | cut -c1-7) - echo json_output=$out >> "$GITHUB_OUTPUT" + set -exuo pipefail + out=$(nix run nixpkgs#nix-prefetch-git -- --url 'https://github.com/${{ github.repository_owner }}/${{ inputs.project }}.git' --rev 'refs/heads/main' --fetch-submodules --quiet | tee output.json) echo sha_short=$(echo $out | jq -r '.rev' | cut -c1-7) >> "$GITHUB_OUTPUT" - name: Update metadata for a project based off the latest upstream git commit @@ -46,9 +45,10 @@ jobs: shell: bash run: | #!/usr/bin/env bash - set -euo pipefail - # Fetch the metadata for the project - json_output="${{ steps.upstream_commit.outputs.json_output }}" + set -exuo pipefail + # Convert the output from previous step to valid JSON format + project=${{ inputs.project }} + json_output=$(cat output.json) # Extract the necessary values from the json_output version=$(echo "$json_output" | jq -r '.version') date=$(echo "$json_output" | jq -r '.date' | awk -F'T' '{print $1}') @@ -60,11 +60,12 @@ jobs: --arg rev "$rev" \ --arg hash "$hash" \ '.version = $version | .rev = $rev | .hash = $hash' \ - ./{{ inputs.project }}/metadata.json | tee ./{{ inputs.project }}/metadata.json.tmp + ./$project/metadata.json | tee ./$project/metadata.json.tmp # Replace the original file - mv ./{{ inputs.project }}/{metadata.json.tmp,metadata.json} + mv ./$project/{metadata.json.tmp,metadata.json} - - uses: EndBug/add-and-commit@main + - name: Commit changes and push + uses: EndBug/add-and-commit@main with: add: "${{ inputs.project }}/metadata.json" commit: --signoff From b25304c55539bd9bfab060b475ba9addbd07c46c Mon Sep 17 00:00:00 2001 From: sumire88 Date: Sun, 25 Aug 2024 21:33:00 +0000 Subject: [PATCH 5/9] chore(dae): pin ref to refs/head/main (00d569f) Signed-off-by: sumire88 --- dae/metadata.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dae/metadata.json b/dae/metadata.json index 60354c4..66b6790 100644 --- a/dae/metadata.json +++ b/dae/metadata.json @@ -1,6 +1,6 @@ { - "version": "v0.7.1", - "rev": "v0.7.1", - "hash": "sha256-A82JwjZTzYvRc0PY2FekRUwLszdCEHv6wcLYHvqwiWU=", + "version": "unstable-2024-08-24.00d569f", + "rev": "00d569f2988868efe2471b2da08c3538c21d3287", + "hash": "sha256-iIPrjZn8JMclQSK6gn3zPqw90x4N7tqK0pWmBe8KaN8=", "vendorHash": "sha256-PCGv1DcOOP2LE5wGmnuB2t3aJP8nqJ/ChafVxeJnRIg=" } From bf2dfa3564a86a31c154d7372a61871481f91f52 Mon Sep 17 00:00:00 2001 From: sumire88 <151038614+sumire88@users.noreply.github.com> Date: Sun, 25 Aug 2024 17:37:14 -0400 Subject: [PATCH 6/9] fix: rename file ext --- .github/workflows/{sync-upstream.yaml => sync-upstream.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{sync-upstream.yaml => sync-upstream.yml} (100%) diff --git a/.github/workflows/sync-upstream.yaml b/.github/workflows/sync-upstream.yml similarity index 100% rename from .github/workflows/sync-upstream.yaml rename to .github/workflows/sync-upstream.yml From 147357f1f7eddacccb0ef8f85b70c94628da8a95 Mon Sep 17 00:00:00 2001 From: sumire88 <151038614+sumire88@users.noreply.github.com> Date: Sun, 25 Aug 2024 17:42:33 -0400 Subject: [PATCH 7/9] ci: add branch input param --- .github/workflows/sync-upstream.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml index 5c0305b..fc49da2 100644 --- a/.github/workflows/sync-upstream.yml +++ b/.github/workflows/sync-upstream.yml @@ -10,6 +10,10 @@ on: - dae - daed required: true + branch: + type: string + description: branch to sync with + default: unstable jobs: sync-upstream: @@ -26,6 +30,7 @@ jobs: - uses: actions/checkout@main with: token: ${{ steps.generate_token.outputs.token }} + ref: ${{ inputs.branch }} - uses: DeterminateSystems/nix-installer-action@main - uses: DeterminateSystems/magic-nix-cache-action@main From 797cce8d5ceb886b463c03df050dc0ce5d8dc28e Mon Sep 17 00:00:00 2001 From: sumire88 <151038614+sumire88@users.noreply.github.com> Date: Sun, 25 Aug 2024 17:48:13 -0400 Subject: [PATCH 8/9] chore(metadata): revert metadata changes --- dae/metadata.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dae/metadata.json b/dae/metadata.json index 66b6790..60354c4 100644 --- a/dae/metadata.json +++ b/dae/metadata.json @@ -1,6 +1,6 @@ { - "version": "unstable-2024-08-24.00d569f", - "rev": "00d569f2988868efe2471b2da08c3538c21d3287", - "hash": "sha256-iIPrjZn8JMclQSK6gn3zPqw90x4N7tqK0pWmBe8KaN8=", + "version": "v0.7.1", + "rev": "v0.7.1", + "hash": "sha256-A82JwjZTzYvRc0PY2FekRUwLszdCEHv6wcLYHvqwiWU=", "vendorHash": "sha256-PCGv1DcOOP2LE5wGmnuB2t3aJP8nqJ/ChafVxeJnRIg=" } From e9963d35f17f4a85a7a6b729d436ece042d31cc3 Mon Sep 17 00:00:00 2001 From: sumire88 <151038614+sumire88@users.noreply.github.com> Date: Sun, 25 Aug 2024 21:25:07 -0400 Subject: [PATCH 9/9] ci(sync-upstream): add build stage --- .github/workflows/sync-upstream.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml index fc49da2..bd60234 100644 --- a/.github/workflows/sync-upstream.yml +++ b/.github/workflows/sync-upstream.yml @@ -75,3 +75,9 @@ jobs: add: "${{ inputs.project }}/metadata.json" commit: --signoff message: "chore(${{ inputs.project }}): pin ref to refs/head/main (${{ steps.upstream_commit.outputs.sha_short }})" + + - name: Build + run: | + #!/usr/bin/env bash + set -exuo pipefail + nix build .#${{ inputs.project }}