-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
120 lines (108 loc) · 4.78 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: "Copy remote file and publish to Maven repo"
description: "This GitHub Action copies a file using a remote URL and publishes it to a Maven repository"
inputs:
artifact_repo:
description: "GitHub repository to publish artifacts"
required: true
gh_pat:
description: "Personal Access Token for GitHub Maven artifact repository"
required: true
artifact_url:
description: "Remote file URL to download from"
required: true
artifact_id:
description: "Artifact ID"
required: true
group_id:
description: "Group ID"
required: true
version:
description: "Version"
required: true
runs:
using: "composite"
steps:
- name: Install xmlstarlet
run: sudo apt-get install -y xmlstarlet
shell: bash
- name: Set environment variables
run: |
echo "GROUPID_PATH=$(echo '${{ inputs.group_id }}' | tr '.' '/')" >> $GITHUB_ENV
ORIGINAL_FILENAME=$(basename ${{ inputs.artifact_url }})
EXTENSION="${ORIGINAL_FILENAME##*.}"
echo "EXTENSION=$EXTENSION" >> $GITHUB_ENV
shell: bash
- name: Checkout artifact repo
uses: actions/checkout@v4
with:
repository: ${{ inputs.artifact_repo }}
token: ${{ inputs.gh_pat }}
- name: Create package directories
run: mkdir -p ${{ env.GROUPID_PATH }}/${{ inputs.artifact_id }}/${{ inputs.version }}
shell: bash
- name: Download artifact
run: |
wget -O ${{ env.GROUPID_PATH }}/${{ inputs.artifact_id }}/${{ inputs.version }}/${{ inputs.artifact_id }}-${{ inputs.version }}.${{ env.EXTENSION }} ${{ inputs.artifact_url }}
shell: bash
- name: Generate Metadata
run: |
TIMESTAMP=$(date +"%Y%m%d%H%M%S")
cat <<EOF > "${{ env.GROUPID_PATH }}/${{ inputs.artifact_id }}/maven-metadata.xml"
<metadata>
<groupId>${{ inputs.group_id }}</groupId>
<artifactId>${{ inputs.artifact_id }}</artifactId>
<versioning>
<latest>${{ inputs.version }}</latest>
<release>${{ inputs.version }}</release>
<versions>
<version>${{ inputs.version }}</version>
</versions>
<lastUpdated>${TIMESTAMP}</lastUpdated>
</versioning>
</metadata>
EOF
shell: bash
- name: Generate POM file
run: |
cat <<EOF > ${{ env.GROUPID_PATH }}/${{ inputs.artifact_id }}/${{ inputs.version }}/${{ inputs.artifact_id }}-${{ inputs.version }}.pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${{ inputs.group_id }}</groupId>
<artifactId>${{ inputs.artifact_id }}</artifactId>
<version>${{ inputs.version }}</version>
</project>
EOF
shell: bash
- name: Extract artifactId, groupId, version from generated POM file
run: |
xml_file=${{ env.GROUPID_PATH }}/${{ inputs.artifact_id }}/${{ inputs.version }}/${{ inputs.artifact_id }}-${{ inputs.version }}.pom
VERSION=$(xmlstarlet sel -N xmlns="http://maven.apache.org/POM/4.0.0" -t -v "//xmlns:project/xmlns:version" "$xml_file")
GROUPID=$(xmlstarlet sel -N xmlns="http://maven.apache.org/POM/4.0.0" -t -v "//xmlns:project/xmlns:groupId" "$xml_file" | sed 's/\./\//g')
ARTIFACTID=$(xmlstarlet sel -N xmlns="http://maven.apache.org/POM/4.0.0" -t -v "//xmlns:project/xmlns:artifactId" "$xml_file")
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "GROUPID=$GROUPID" >> $GITHUB_ENV
echo "ARTIFACTID=$ARTIFACTID" >> $GITHUB_ENV
shell: bash
- name: Generate checksums
run: |
ARTIFACT_PATH=${{ env.GROUPID_PATH }}/${{ inputs.artifact_id }}/${{ inputs.version }}/${{ inputs.artifact_id }}-${{ inputs.version }}
# Generate checksums for the artifact and POM
sha1sum "$ARTIFACT_PATH.${{ env.EXTENSION }}" > "$ARTIFACT_PATH.${{ env.EXTENSION }}.sha1"
md5sum "$ARTIFACT_PATH.${{ env.EXTENSION }}" > "$ARTIFACT_PATH.${{ env.EXTENSION }}.md5"
sha1sum "$ARTIFACT_PATH.pom" > "$ARTIFACT_PATH.pom.sha1"
md5sum "$ARTIFACT_PATH.pom" > "$ARTIFACT_PATH.pom.md5"
shell: bash
- name: Commit and push files
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor_id }}+${{ github.actor }}@users.noreply.github.com"
git add .
git commit -m "Added artifacts for ${{ env.ARTIFACTID }} version ${{ env.VERSION }}"
shell: bash
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ inputs.gh_pat }}
repository: ${{ inputs.artifact_repo }}
force_with_lease: true