WORKFLOW: reworked cooker workflow to ensure that RetroDECK Organization related patterns are not executed on a foregin repository making it fail

This commit is contained in:
XargonWan 2024-08-21 13:49:49 +09:00
parent a26aafabef
commit b4253b7f10

View file

@ -41,6 +41,7 @@ jobs:
continue-on-error: true continue-on-error: true
- name: Generate a token for Rekku - name: Generate a token for Rekku
if: github.repository_owner == 'RetroDECK'
id: generate-rekku-token id: generate-rekku-token
uses: actions/create-github-app-token@v1 uses: actions/create-github-app-token@v1
with: with:
@ -52,6 +53,8 @@ jobs:
- name: Clone RetroDECK repo - name: Clone RetroDECK repo
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
ref: ${{ github.event.pull_request.head.ref || github.ref }} # Use the branch or commit reference from the pull request if available; otherwise, fall back to the reference from the event that triggered the workflow.
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} # Use the repository name from the pull request if available; otherwise, use the repository name from the event that triggered the workflow.
submodules: 'true' submodules: 'true'
- name: "Install dependencies" - name: "Install dependencies"
@ -73,22 +76,30 @@ jobs:
echo "MAKE_LATEST=true" >> $GITHUB_ENV echo "MAKE_LATEST=true" >> $GITHUB_ENV
fi fi
# if the branch is coming from a PR the tag should be manually built # Generate version tag based on the branch name: if the branch is coming from a PR the tag should be manually built
- name: "Generate version tag" - name: "Generate version tag"
run: | run: |
# Source version extractor script and get manifest version
source automation_tools/version_extractor.sh source automation_tools/version_extractor.sh
MANIFEST_VERSION="$(fetch_manifest_version)" MANIFEST_VERSION="$(fetch_manifest_version)"
# Set manifest version to environment variable
echo "MANIFEST_VERSION=$MANIFEST_VERSION" >> $GITHUB_ENV echo "MANIFEST_VERSION=$MANIFEST_VERSION" >> $GITHUB_ENV
if [[ "$BRANCH_NAME" == 'refs/'* ]]; then
pr_number=$(echo ${{env.BRANCH_NAME}} | awk -F'/' '{print $3}') # Determine tag based on branch type
source_branch=$(curl -s "https://api.github.com/repos/RetroDECK/RetroDECK/pulls/$pr_number" | jq -r '.head.ref') if [[ "$BRANCH_NAME" == refs/* ]]; then
source_branch=${source_branch//\//-} pr_number=$(echo "${{ env.BRANCH_NAME }}" | awk -F'/' '{print $3}')
echo "[DEBUG] source branch is: $source_branch" source_branch=$(curl -s "https://api.github.com/repos/RetroDECK/RetroDECK/pulls/$pr_number" | jq -r '.head.ref' | tr '/' '-')
echo "TAG=PR-$pr_number-$source_branch-${{ env.buildid }}" >> $GITHUB_ENV TAG="PR-$pr_number-$source_branch-${{ env.buildid }}"
else else
TAG="$MANIFEST_VERSION-${{ env.buildid }}" TAG="$MANIFEST_VERSION-${{ env.buildid }}"
echo "TAG=$TAG" >> $GITHUB_ENV
fi fi
# Set tag to environment variable
echo "TAG=$TAG" >> $GITHUB_ENV
# Output debug information
echo "MANIFEST_VERSION: $MANIFEST_VERSION" echo "MANIFEST_VERSION: $MANIFEST_VERSION"
echo "Version TAG: $TAG" echo "Version TAG: $TAG"
@ -129,10 +140,6 @@ jobs:
- name: Create Bundle - name: Create Bundle
run: "/bin/bash ${GITHUB_WORKSPACE}/automation_tools/flatpak_build_bundle.sh" run: "/bin/bash ${GITHUB_WORKSPACE}/automation_tools/flatpak_build_bundle.sh"
- name: Set environment variable with current branch name
run: echo "GITHUB_REF_SLUG=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
- name: Get commits since last release - name: Get commits since last release
run: | run: |
# Get the latest release tag # Get the latest release tag
@ -140,21 +147,21 @@ jobs:
# Get all commits since the latest release tag # Get all commits since the latest release tag
COMMITS=$(git log $LATEST_TAG..HEAD --pretty=format:"- %s") COMMITS=$(git log $LATEST_TAG..HEAD --pretty=format:"- %s")
# Set the output variable # Set the output variable
echo "::set-output name=commits::$COMMITS" echo "COMMITS=$COMMITS" >> $GITHUB_ENV
id: commits
continue-on-error: true continue-on-error: true
- name: Publish the flatpak in a new cooker release - name: Publish the flatpak in a new cooker release
uses: ncipollo/release-action@v1 uses: ncipollo/release-action@v1
with: with:
tag: "${{env.TAG}}" tag: "${{env.TAG}}"
commit: ${{ github.sha }}
body: | body: |
# Release Notes (Cooker) # Release Notes (Cooker)
This is a cooker snapshot based on the commit: ${{ github.event.repository.full_name }}@${{github.sha}}. This is a cooker snapshot based on the commit: ${{ github.event.repository.full_name }}@${{github.sha}}.
On branch [${{env.BRANCH_NAME}}](https://github.com/RetroDECK/RetroDECK/tree/${{env.BRANCH_NAME}}). On branch [${{env.BRANCH_NAME}}](https://github.com/RetroDECK/RetroDECK/tree/${{env.BRANCH_NAME}}).
## Commits since last release ## Commits since last cooker build
${{ steps.commits.outputs.commits }} ${{ env.COMMITS }}
For the full release note for this build please refer to the channel [#BETA-TESTING](https://discord.gg/WDc5C9YWMx) on our Discord server. For the full release note for this build please refer to the channel [#BETA-TESTING](https://discord.gg/WDc5C9YWMx) on our Discord server.
@ -165,10 +172,11 @@ jobs:
allowUpdates: true allowUpdates: true
makeLatest: ${{env.MAKE_LATEST}} # if it's a feat branch is not considered the latest build makeLatest: ${{env.MAKE_LATEST}} # if it's a feat branch is not considered the latest build
token: ${{ steps.generate-rekku-token.outputs.token }} token: ${{ steps.generate-rekku-token.outputs.token }}
repo: Cooker repo: ${{ github.repository_owner == 'RetroDECK' && 'Cooker' || github.repository }} # If the repo owner is RetroDECK, publish to Cooker, otherwise publish to the current fork repo
continue-on-error: true continue-on-error: true
- name: Rewrite Tag - name: Rewrite Tag
if: github.repository_owner == 'RetroDECK'
run: | run: |
git submodule deinit -f --all git submodule deinit -f --all
git fetch --tags git fetch --tags
@ -192,6 +200,7 @@ jobs:
continue-on-error: true continue-on-error: true
- name: Create Artifact for flathub - name: Create Artifact for flathub
if: github.repository_owner == 'RetroDECK'
run: | run: |
tar -czf ${GITHUB_WORKSPACE}/RetroDECK-Artifact-cooker.tar.gz -C ${GITHUB_WORKSPACE}/retrodeck-flatpak-cooker . tar -czf ${GITHUB_WORKSPACE}/RetroDECK-Artifact-cooker.tar.gz -C ${GITHUB_WORKSPACE}/retrodeck-flatpak-cooker .
hash=($(sha256sum ${GITHUB_WORKSPACE}/RetroDECK-Artifact-cooker.tar.gz)) hash=($(sha256sum ${GITHUB_WORKSPACE}/RetroDECK-Artifact-cooker.tar.gz))
@ -200,6 +209,7 @@ jobs:
continue-on-error: true continue-on-error: true
# - name: Upload RetroDECK-cooker.flatpak to Gitea Release # - name: Upload RetroDECK-cooker.flatpak to Gitea Release
# if: github.repository_owner == 'RetroDECK'
# run: | # run: |
# # Set variables for Gitea host, organization, repository, access token, and release details # # Set variables for Gitea host, organization, repository, access token, and release details
# GITEA_HOST="repo.retrodeck.net" # GITEA_HOST="repo.retrodeck.net"