|
18 | 18 |
|
19 | 19 | permissions: |
20 | 20 | contents: write |
| 21 | + packages: write |
21 | 22 |
|
22 | 23 | jobs: |
23 | 24 | build_memory_footprint: |
@@ -61,11 +62,90 @@ jobs: |
61 | 62 | with: |
62 | 63 | repo_token: "${{ secrets.GITHUB_TOKEN }}" |
63 | 64 | automatic_release_tag: "${{ inputs.release_name }}" |
64 | | - prerelease: true |
| 65 | + prerelease: false |
65 | 66 | title: "Memory Footprint Build" |
66 | 67 | files: | |
67 | 68 | memory-footprint_LICENSE.txt |
68 | 69 | wff-validator_LICENSE.txt |
69 | 70 | **/memory-footprint.jar |
70 | 71 | **/wff-validator.jar |
71 | 72 | **/wff-xsd.zip |
| 73 | +
|
| 74 | + publish_packages: |
| 75 | + runs-on: ubuntu-latest |
| 76 | + needs: build_memory_footprint |
| 77 | + env: |
| 78 | + GH_TOKEN: ${{ github.token }} |
| 79 | + strategy: |
| 80 | + matrix: |
| 81 | + jar_file: [wff-validator.jar, memory-footprint.jar] |
| 82 | + steps: |
| 83 | + - name: Install GitHub CLI |
| 84 | + run: | |
| 85 | + sudo apt-get update |
| 86 | + sudo apt-get install gh |
| 87 | + - name: Download asset |
| 88 | + run: | |
| 89 | + gh release download --repo "$GITHUB_REPOSITORY" --pattern ${{ matrix.jar_file }} |
| 90 | + - name: Get JAR version |
| 91 | + id: get_version |
| 92 | + run: | |
| 93 | + VERSION=$(unzip -p ${{ matrix.jar_file }} META-INF/MANIFEST.MF | grep "^Version: " | cut -d' ' -f2) |
| 94 | + if [[ -z "$VERSION" ]]; then |
| 95 | + echo "::error file=${{ matrix.jar_file }}::Could not determine version from JAR's Manifest file" |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + echo "::set-output name=version::$VERSION" |
| 99 | + - name: Determine final version |
| 100 | + id: final_version |
| 101 | + run: | |
| 102 | + VERSION="${{ steps.get_version.outputs.version }}" |
| 103 | + if ${{ inputs.release_name == 'latest' }}; then |
| 104 | + VERSION="$VERSION-SNAPSHOT" |
| 105 | + fi |
| 106 | + echo "::set-output name=final_version::$VERSION" |
| 107 | + - name: Determine artefact ID |
| 108 | + id: artefact_id |
| 109 | + run: | |
| 110 | + FILE_NAME="${{ matrix.jar_file }}" |
| 111 | + FILE_NAME_WITHOUT_EXTENSION="${FILE_NAME%.*}" |
| 112 | + echo "::set-output name=artefact_id::$FILE_NAME_WITHOUT_EXTENSION" |
| 113 | + - name: Check if Maven package already exists |
| 114 | + id: check_exists |
| 115 | + run: | |
| 116 | + VERSION="${{ steps.final_version.outputs.final_version }}" |
| 117 | + ARTEFACT_ID=${{ steps.artefact_id.outputs.artefact_id }} |
| 118 | +
|
| 119 | + METADATA_URL="https://maven.pkg.github.com/google/watchface/com.google.watchface/${ARTIFACT_ID}/${VERSION}/maven-metadata.xml" |
| 120 | +
|
| 121 | + if ${{ inputs.release_name == 'latest' }}; then |
| 122 | + # SNAPSHOT version should always publish |
| 123 | + echo "::set-output name=should_publish::true" |
| 124 | + elif curl -s -f -o /dev/null -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "$METADATA_URL"; then |
| 125 | + # Don't republish existing non-SNAPSHOT versions |
| 126 | + echo "Maven package with version $VERSION already exists." |
| 127 | + else |
| 128 | + echo "Maven package with version $VERSION does not exist." |
| 129 | + echo "::set-output name=should_publish::true" |
| 130 | + fi |
| 131 | + - name: create settings.xml |
| 132 | + if: steps.check_exists.outputs.should_publish == 'true' |
| 133 | + run: | |
| 134 | + mkdir -p ~/.m2 |
| 135 | + echo "<settings><servers><server><id>github</id><configuration><httpHeaders><property><name>Authorization</name><value>Bearer ${{ secrets.GITHUB_TOKEN }}</value></property></httpHeaders></configuration></server></servers></settings>" > ~/.m2/settings.xml |
| 136 | + shell: bash |
| 137 | + env: |
| 138 | + GITHUB_PATH: ~/.m2/ |
| 139 | + - name: Publish to GitHub Packages |
| 140 | + if: steps.check_exists.outputs.should_publish == 'true' |
| 141 | + run: | |
| 142 | + mvn deploy:deploy-file \ |
| 143 | + -DgroupId=com.google.watchface \ |
| 144 | + -DartifactId=${{ steps.artefact_id.outputs.artefact_id }} \ |
| 145 | + -Dversion=${{ steps.final_version.outputs.final_version }} \ |
| 146 | + -Dpackaging=jar \ |
| 147 | + -Dfile=${{ matrix.jar_file }} \ |
| 148 | + -Durl=https://maven.pkg.github.com/google/watchface \ |
| 149 | + -DrepositoryId=github -s ~/.m2/settings.xml |
| 150 | + env: |
| 151 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments