Skip to content

Fix deploy artifacts for branches with slash in name #224

Fix deploy artifacts for branches with slash in name

Fix deploy artifacts for branches with slash in name #224

Workflow file for this run

name: Build
on:
pull_request: # all PRs
push:
branches:
- master
- develop
env:
JAVA_DISTRIBUTION: "temurin"
JAVA_VERSION: "17"
GRADLE_BUILD_ACTION_CACHE_DEBUG_ENABLED: true
ACTIONS_STEP_DEBUG: true
ARTIFACT_TTL: 1
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ contains(github.ref, 'refs/pull/')}}
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- { name: Fetch sources, uses: actions/checkout@v4, with: { fetch-depth: 0 } }
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- { name: Gradle Wrapper Validation, uses: gradle/wrapper-validation-action@v3 }
- { name: Set up JDK, uses: actions/setup-java@v4, with: { distribution: "${{ env.JAVA_DISTRIBUTION }}", java-version: "${{ env.JAVA_VERSION }}" } }
- { name: Setup Gradle, uses: gradle/actions/setup-gradle@v3, with: { gradle-home-cache-cleanup: true } }
- name: Build plugin
run: ./gradlew buildPlugin
- { name: Upload `compiled` artifact, uses: actions/upload-artifact@v4, with: { name: compiled, path: build/classes/**/*, retention-days: "${{ env.ARTIFACT_TTL }}" } }
testing:
name: Test with coverage
runs-on: ubuntu-latest
needs: [build]
steps:
- { name: Fetch sources, uses: actions/checkout@v4, with: { fetch-depth: 0 } }
- { name: Set up JDK, uses: actions/setup-java@v4, with: { distribution: "${{ env.JAVA_DISTRIBUTION }}", java-version: "${{ env.JAVA_VERSION }}" } }
- { name: Setup Gradle, uses: gradle/actions/setup-gradle@v3, with: { gradle-home-cache-cleanup: true } }
- { name: Download `compiled`, uses: actions/download-artifact@v4, with: { name: compiled, path: build/classes/ } }
- name: Run tests
run: ./gradlew check
- { name: Upload `junit-report` artifact, uses: actions/upload-artifact@v4, with: { name: junit-report, path: build/reports/junit, retention-days: "${{ env.ARTIFACT_TTL }}" } }
- { name: Upload `jacoco-report` artifact, uses: actions/upload-artifact@v4, with: { name: jacoco-report, path: build/reports/jacoco, retention-days: "${{ env.ARTIFACT_TTL }}" } }
sonarQube:
name: SonarQube
runs-on: ubuntu-latest
needs: [testing]
steps:
- { name: Fetch sources, uses: actions/checkout@v4, with: { fetch-depth: 0 } }
- { name: Set up JDK, uses: actions/setup-java@v4, with: { distribution: "${{ env.JAVA_DISTRIBUTION }}", java-version: "${{ env.JAVA_VERSION }}" } }
- { name: Setup Gradle, uses: gradle/actions/setup-gradle@v3, with: { gradle-home-cache-cleanup: true } }
- { name: Download `junit-report`, uses: actions/download-artifact@v4, with: { name: junit-report, path: build/reports/junit } }
- { name: Download `jacoco-report`, uses: actions/download-artifact@v4, with: { name: jacoco-report, path: build/reports/jacoco } }
- { name: Download `compiled`, uses: actions/download-artifact@v4, with: { name: compiled, path: build/classes/ } }
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Run SonarQube analysis with Quality Gates
if: github.ref != 'refs/heads/master'
run: ./gradlew sonar -Dsonar.branch.name=${{ github.head_ref }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Run SonarQube analysis
if: github.ref == 'refs/heads/master'
run: ./gradlew sonar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_SCANNER_OPTS: "-Dsonar.qualitygate.wait=true -Dsonar.projectVersion=$CI_COMMIT_TAG"
checkApiVersion:
name: Check API version
runs-on: ubuntu-latest
steps:
- { name: Fetch sources, uses: actions/checkout@v4, with: { fetch-depth: 0 } }
- name: Parse last exists API version
run: >-
curl https://lua-api.factorio.com/latest/runtime-api.json 2>/dev/null \
| jq .application_version \
| tr -d '"' \
| { read VAR; echo "LAST_API_VERSION=$VAR" >> $GITHUB_ENV; }
- name: Parse last supported API version
run: >-
grep "supportedApiVersions.max" src/main/resources/FactorioApiCompletion.properties \
| awk -F '=' '{print $2}' \
| { read VAR; echo "LAST_SUPPORTED_API_VERSION=$VAR" >> $GITHUB_ENV; }
- name: Fail if not support latest version
if: ${{ env.LAST_API_VERSION != env.LAST_SUPPORTED_API_VERSION }}
uses: actions/github-script@v3
with:
script: core.setFailed('Plugin not support latest API version')
verifyPlugin:
name: Verify Plugin
runs-on: ubuntu-latest
needs: [sonarQube]
steps:
- { name: Fetch sources, uses: actions/checkout@v4, with: { fetch-depth: 0 } }
- { name: Set up JDK, uses: actions/setup-java@v4, with: { distribution: "${{ env.JAVA_DISTRIBUTION }}", java-version: "${{ env.JAVA_VERSION }}" } }
- { name: Setup Gradle, uses: gradle/actions/setup-gradle@v3, with: { gradle-home-cache-cleanup: true } }
- name: Run Plugin Verify
run: ./gradlew runPluginVerifier
- { name: Upload `intellij-verification-report` artifact, uses: actions/upload-artifact@v4, with: { name: intellij-verification-report, path: build/reports/pluginVerifier, retention-days: "${{ env.ARTIFACT_TTL }}" } }
prepare-deploy-artifacts:
name: Prepare deploy reports
needs: [ testing, verifyPlugin ]
runs-on: ubuntu-latest
steps:
- { name: Get branch names, id: branch-names, uses: tj-actions/branch-names@v8 }
- name: Save branch name in env
run: echo 'REPORT_BRANCH=${{ steps.branch-names.outputs.current_branch }}' | sed 's/\//-/g' >> $GITHUB_ENV
- { name: Download `junit-report`, uses: actions/download-artifact@v4, with: { name: junit-report, path: "var/${{ env.REPORT_BRANCH }}/reports/junit" } }
- { name: Download `jacoco-report`, uses: actions/download-artifact@v4, with: { name: jacoco-report, path: "var/${{ env.REPORT_BRANCH }}/reports/jacoco" } }
- { name: Download `intellij-verification-report`, uses: actions/download-artifact@v4, with: { name: intellij-verification-report, path: "var/${{ env.REPORT_BRANCH }}/reports/pluginVerifier" } }
- name: Generate Directory Listings
uses: jayanta525/github-pages-directory-listing@v4.0.0
with:
FOLDER: "var/${{ env.REPORT_BRANCH }}/reports"
- { name: Upload `github-pages-raw` artifact, uses: actions/upload-artifact@v4, with: { name: github-pages-raw, path: "var/", retention-days: "${{ env.ARTIFACT_TTL }}" } }
deploy-artifacts:
name: Deploy reports
needs: [prepare-deploy-artifacts]
concurrency:
group: ${{ github.repository }}/deploy-artifacts
cancel-in-progress: false
permissions:
pages: write
id-token: write
statuses: write
env:
GH_TOKEN: ${{ github.token }}
REPORT_COMMIT: ${{ github.event.pull_request.head.sha || github.event.after }}
environment:
name: github-pages
runs-on: ubuntu-latest
steps:
- { name: Fetch sources, uses: actions/checkout@v4, with: { fetch-depth: 0 } }
- { name: Get branch names, id: branch-names, uses: tj-actions/branch-names@v8 }
- name: Save branch name in env
run: echo 'REPORT_BRANCH=${{ steps.branch-names.outputs.current_branch }}' | sed 's/\//-/g' >> $GITHUB_ENV
- name: Download all page artifacts
shell: bash
run: >-
set -e;
set -o xtrace;
gh api \
-H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/actions/artifacts?name=github-pages-raw\&per_page=100 \
| jq ".artifacts | [ .[] | select(.expired == false) ]" \
| jq "[ .[] | {id: .id, branch: .workflow_run.head_branch, created: .created_at} ]" \
| jq "group_by(.branch) | map(max_by(.created))" \
| jq ".[] | [.id, .branch] | @tsv" \
| tr -d '"' \
| sed -E 's/\\t/\,/g' \
| while IFS="," read -r id branch; \
do \
BRANCH=$(echo $branch | sed 's/\//-/g')
gh api \
-H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/actions/artifacts/$id/zip > $BRANCH.zip; \
unzip -d var/ $BRANCH.zip; \
rm $BRANCH.zip; \
done
- name: Generate Directory Listings
uses: jayanta525/github-pages-directory-listing@v4.0.0
with:
FOLDER: "var/"
- name: Prepare artifact for GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: var/
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
- run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/statuses/${{ env.REPORT_COMMIT }} \
-f "state=success" \
-f "target_url=${{ steps.deployment.outputs.page_url }}${{ env.REPORT_BRANCH }}/reports" \
-f "description=Reports on Github Pages" \
-f "context=${{ github.workflow }}"